Question

Generate client from CDF openapi spec for Go

  • 30 November 2023
  • 0 replies
  • 54 views

I am unable to generate client code for the CDF openapi spec at https://api-docs.cognite.com/20230101/ using deepmap/oapi-codegen for Go, seemingly because the spec contains some errors. Do anyone know of a way to generate an api-client in go for the CDF-api spec?

 

Both commands below rely on having openapi spec downloaded to the current directory from https://api-docs.cognite.com/20230101/

 

Testing the spec for errors with redocly/cli: docker run --rm -it -v $PWD/swagger.json:/swagger.json redocly/cli lint /swagger.json

For me this results in “Validation failed with 25 errors and 382 warnings”

 

Generating the client library using deepmap/oapi-codegen: go run github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@v2.0.0 --config oapi-codegen-config.yaml swagger.json

with the this config file:

package: "cdf_api"
output: "cdf_api.gen.go"
generate:
models: true
client: true
compatibility:
circular-reference-limit: 100

For me this results in the message “error generating code: error creating operation definitions: path '/documents/search' has 0 positional parameters, but spec has 1 declared” - I started fixing some errors, but there was quite a few of them, so I stopped.

 

 


0 replies

Be the first to reply!

Reply