Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAPI Response YAML file response status codes most be a string #907

Open
1 task done
twickstrom opened this issue Oct 28, 2024 · 1 comment · May be fixed by #908
Open
1 task done

OpenAPI Response YAML file response status codes most be a string #907

twickstrom opened this issue Oct 28, 2024 · 1 comment · May be fixed by #908
Labels
bug Something isn't working validated

Comments

@twickstrom
Copy link

Scribe version

4.38

PHP version

8.3.12

Framework

Laravel

Framework version

11.29

Scribe config

title => "The Fabric API"
base_url => "http://127.0.0.1:8000"
type => "external_static"
theme => "scalar"
static.output_path => "storage/scribe/docs"
laravel.add_routes => false
auth.enabled => true
auth.default => true
auth.name => "Authorization"
logo => "https://assets.whatsfabric.com/images/fabric-red-horizontal.svg"
strategies.queryParameters => added App\Docs\Strategies\QueryParameters\AddJsonApiQueryParameters

What happened?

My openapi.yaml file is failing validation and is not able to be used by some third party tools for easier front end developement.

OpenAPI can be represented canonically in either JSON or YAML, as you say in JSON only strings can be keys. With regard to YAML:

This field MUST be enclosed in quotation marks (for example, "200") for compatibility between JSON and YAML.

This has the effect that the key is always a string type.

See OAI/OpenAPI-Specification#1752

The good news is this is a very easy fix.

Knuckles\Scribe\Writing\Writer:27

Current:
return Yaml::dump($spec, 20, 2, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_OBJECT_AS_MAP);

New:
return Yaml::dump($spec, 20, 2, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_OBJECT_AS_MAP | Yaml::DUMP_NUMERIC_KEY_AS_STRING);

I would also recommend allowing OAS contact info to be added optionally:
config\scribe.php

'contact' => [
    'name' => 'Company Name',
    'url' => 'URL',
    'email' => 'EMAIL',
],

Knuckles\Scribe\Writing\OpenAPISpecWriter
Current:

'info' => [
    'title' => $this->config->get('title') ?: config('app.name', ''),
    'description' => $this->config->get('description', ''),
    'version' => '1.0.0',
],

New:

'info' => [
    'title' => $this->config->get('title') ?: config('app.name', ''),
    'description' => $this->config->get('description', ''),
    'version' => config('app.version', ''),
    'contact' => [
        'name' => $this->config->get('contact.name', ''),
        'url' => $this->config->get('contact.url', ''),
        'email' => $this->config->get('contact.email', ''),
    ],
],

Docs

@twickstrom twickstrom added bug Something isn't working triage labels Oct 28, 2024
@twickstrom twickstrom linked a pull request Oct 28, 2024 that will close this issue
@twickstrom
Copy link
Author

PR submitted #908

@shalvah shalvah added validated and removed triage labels Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working validated
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants