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

Pet Store is serving up teapots #1

Open
philsturgeon opened this issue Jul 27, 2018 · 7 comments
Open

Pet Store is serving up teapots #1

philsturgeon opened this issue Jul 27, 2018 · 7 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed upstream

Comments

@philsturgeon
Copy link

philsturgeon commented Jul 27, 2018

Hey Daniel! Trying out this awesome thing and getting teapot responses instead of valid mocks:

docker run -p 8000:8000 danielgtaylor/apisprout https://raw.githubusercontent.com/OAI/OpenAPI-Specification/OpenAPI.next/examples/v3.0/petstore.yaml

Responses:

http --json GET http://localhost:8000/pets
HTTP/1.1 418 I'm a teapot
Content-Length: 21
Content-Type: text/plain; charset=utf-8
Date: Fri, 27 Jul 2018 14:23:04 GMT

No example available.

Any ideas? The --json switch sets Accept: application/json which I assume is how you determine the responses. Had the same problem in Postman.

@danielgtaylor
Copy link
Owner

danielgtaylor commented Jul 27, 2018

@philsturgeon the petstore.yaml document is missing examples. I don't yet generate fake data based on the schema, so for now you need to provide an example or examples to get anything back.

I'd like to add schema -> example generation code, but it's never going to be anywhere near as good as a real example. Even the popular json-schema-faker package for Node suggests adding additional hint fields to the schema because of the same reason.

It might be helpful if you could provide examples of what sort of response you would expect from the linked petstore spec.

@danielgtaylor danielgtaylor added the question Further information is requested label Jul 27, 2018
@danielgtaylor danielgtaylor self-assigned this Jul 27, 2018
@philsturgeon
Copy link
Author

philsturgeon commented Jul 27, 2018

Ah of course, my mistake. I'm so used to tools like ReDoc just shoving "string" in for strings, etc, that I'm used to everything working. I was just trying to get a hello-world done with a URL using any schema from anywhere.

Using one that's been resolved through Speccy (oas-kit under the hood) I get this:

docker run -p 8000:8000 -v /Users/philsturgeon/src/hackathon-apis/generated/specs/airlock/openapi.yml:/api.yaml danielgtaylor/apisprout /api.yaml
2018/07/27 17:40:58 expected prefix '#/components/schemas/' in URI '#/paths/~1v1~1servers/get/responses/200/content/application~1json/schema/properties/meta'

Attempting to use a sample file from a friend which does have examples, I'm getting this:

▶ docker run -p 8000:8000 danielgtaylor/apisprout https://raw.githubusercontent.com/hskrasek/conference-api-docs/master/specs/openapi.yaml
2018/07/27 17:42:42 error unmarshaling JSON: Error while unmarshalling property 'components' (*openapi3.Components): Error while unmarshalling property 'responses' (*map[string]*openapi3.ResponseRef): Error while unmarshalling property 'content' (*openapi3.Content): Error while unmarshalling property 'schema' (*openapi3.SchemaRef): Error while unmarshalling property 'properties' (*map[string]*openapi3.SchemaRef): Error while unmarshalling property 'items' (*openapi3.SchemaRef): Error while unmarshalling property 'discriminator' (*string): json: cannot unmarshal object into Go value of type string

It's a valid file according to Swagger Editor.

screen shot 2018-07-27 at 1 44 27 pm

Got any sample files around I can use which will work? I want to verify the functionality so I can merge your openapi.tools PR.

@danielgtaylor
Copy link
Owner

These look like bugs in the underlying parser library. For now I have opened:

I'll swing back and provide an example as I have time later. May also try to tackle some of the issues above when I get some time, too. I think the discriminator one is an easy fix.

@philsturgeon
Copy link
Author

Thank you. I've merged it up onto openapi.tools now outta trust. :)

@danielgtaylor danielgtaylor added bug Something isn't working upstream help wanted Extra attention is needed and removed question Further information is requested labels Oct 4, 2018
@johnrhunt
Copy link

Arg, not much movement on Kin - are there any other libs you could use @danielgtaylor ? Unfortunately I'm not a Go hacker..

@pmundt
Copy link

pmundt commented Jan 5, 2019

@johnrhunt @danielgtaylor I just ran into this same issue and came across this blog post. This would seem to be a point of difference between the Swagger specification and OpenAPI 3.0. While arbitrary strings for the reference object are valid Swagger, they do not seem to be so under OpenAPI 3.0, which places them clearly under components/schemas - hence the error (earlier versions of the Pet Store API placed these under 'definitions', rather than components/schemas, and no longer work, either). I would suggest given OpenAPI 3.0's view on this topic, this should not be considered a bug outright, but some additional guidance to assist people with migration would be helpful, too.

@AbhimanyuG
Copy link

@pmundt I see your point however all resolvers I came across generate such arbitrary references:
$ref: '#/paths/...
If there's a better resolver which strictly adheres to OpenAPI 3.0 standards, this wouldn't be a problem but my search hasn't concluded any such tool so far.

If someone knows such a resolver, please let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed upstream
Projects
None yet
Development

No branches or pull requests

5 participants