Solved

Generate client from CDF openapi spec for Go

  • 30 November 2023
  • 1 reply
  • 75 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.

 

 

icon

Best answer by Dilini Fernando 17 June 2024, 14:08

View original

1 reply

Userlevel 4
Badge +2

Hi @andcondall,

Our product teams are working hard to make sure our APIs meet the OpenAPI spec, but every now and then we might run into some issues. If you come across any specific, critical non-conformities, we'd really appreciate it if you could log a ticket for us or send an email to support@cognite.com . This will help us prioritize and address them properly among other items in our bug backlog.

Reply