stapi
stapi copied to clipboard
Official go client
I would love a client in go, I am willing to help out in this regard.
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
Also it seems that the $ref are being generated incorrectly in the swagger spec:
Please see:
https://github.com/go-swagger/go-swagger/issues/2443#issuecomment-733825983
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 https://github.com/go-swagger/go-swagger/issues/2443#issuecomment-733825983 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.
@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.