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

Official go client #14

Open
richardwooding opened this issue Nov 25, 2020 · 4 comments
Open

Official go client #14

richardwooding opened this issue Nov 25, 2020 · 4 comments

Comments

@richardwooding
Copy link

I would love a client in go, I am willing to help out in this regard.

@richardwooding
Copy link
Author

I'm really struggling with swagger-codegen and the stapi.yml file. With all languages (not just go) it's currently breaking on reading the model.

The following commands

swagger-codegen generate -i stapi.yaml -l java  -o /tmp/java
swagger-codegen generate -i stapi.yaml -l go  -o /tmp/go
swagger-codegen generate -i stapi.yaml -l javascript  -o /tmp/javascript

all experience this when parsing the model

20:06:07.655 [Thread-0] WARN  io.swagger.v3.parser.OpenAPIV3Parser - Exception while resolving:
java.lang.RuntimeException: Could not find definitions/AnimalFullResponse in contents of ./animal/path/animal.path.yaml
	at io.swagger.v3.parser.ResolverCache.loadRef(ResolverCache.java:145)
	at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalSchema(ExternalRefProcessor.java:56)
	at io.swagger.v3.parser.processors.SchemaProcessor.processReferenceSchema(SchemaProcessor.java:214)
	at io.swagger.v3.parser.processors.SchemaProcessor.processSchema(SchemaProcessor.java:37)
	at io.swagger.v3.parser.processors.ResponseProcessor.processResponse(ResponseProcessor.java:52)
	at io.swagger.v3.parser.processors.OperationProcessor.processOperation(OperationProcessor.java:67)
	at io.swagger.v3.parser.processors.PathsProcessor.processPaths(PathsProcessor.java:84)
	at io.swagger.v3.parser.OpenAPIResolver.resolve(OpenAPIResolver.java:49)
	at io.swagger.v3.parser.OpenAPIV3Parser.resolve(OpenAPIV3Parser.java:172)
	at io.swagger.v3.parser.OpenAPIV3Parser.readContents(OpenAPIV3Parser.java:153)
	at io.swagger.v3.parser.OpenAPIV3Parser.readContents(OpenAPIV3Parser.java:99)
	at io.swagger.v3.parser.converter.SwaggerConverter.readResult(SwaggerConverter.java:113)
	at io.swagger.v3.parser.converter.SwaggerConverter.readLocation(SwaggerConverter.java:91)
	at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:16)
	at io.swagger.codegen.v3.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:517)
	at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:376)
	at java.base/java.lang.Thread.run(Thread.java:832)

and subsequently only generate a subset of the client. Only the Animal API

@richardwooding
Copy link
Author

Also it seems that the $ref are being generated incorrectly in the swagger spec:

Please see:

go-swagger/go-swagger#2443 (comment)

@cezarykluczynski
Copy link
Owner

Hi, Richard.

Thanks for taking time investigating this.

When I was writing this, swagger-codegen was especially troublesome around definitions paths. I remember different styles of $refs worked in different versions, and also some of the official examples didn't work as expected. What I came up with here was pretty much what allowed me to generate Java clients.

I understand though that go-swagger is different and it's implemented from scratch in Go. What is proposed in go-swagger/go-swagger#2443 (comment) however:

$ref: '../../stapi.yaml#/definitions/SpacecraftFullResponse'

doesn't work with my version of swagger-codegen and produces an error. Let me first ask some questions on go-swagger issue you've linked, then I'll see if a version of stapi that satisfied both generators can be assembled.

@fredbi
Copy link

fredbi commented Nov 25, 2020

@cezarykluczynski you are welcome to ask questions at https://github.com/go-swagger/go-swagger/issues.

At go-openapi/ & go-swagger we try to abide as much as possible by the jsonschema v4 definition of what a $ref is.

There are some corner cases where we still fail (e.g. complex patterns of cyclic refs, windows paths, etc.) but basically, we get it right for the hundreds of spec and examples that run daily on our CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants