oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

Error generating code for Confluence OpenAPI Spec

Open jesselang opened this issue 2 years ago • 1 comments

Hello. I'm trying to generate a client for the Confluence Cloud REST API based on its OpenAPI Spec. The generation doesn't seem to work. I've tried with v1.11.1 and with the latest commit on the master branch.

Questions:

  • What is the "new config style", and where can I find out more about it?
  • Is it possible to generate a client from this OpenAPI Spec? I'm probably doing something very wrong, but it's not obvious to me.

Thank you very much for any assistance you can provide!

Full Background Story

I tried only generating the types and client code, but was given an error that I'm not sure what to do with.

% oapi-codegen  -generate types,client -package confluence swagger.v3.json
error processing flags: flags --generate aren't supported in new config style, please use --old-config-style or update your configuration

I tried --old-config-style flag as mentioned:

% oapi-codegen -old-config-style -generate types,client -package confluence swagger.v3.json 2>gen.go

It failed, and gen.go contains:

error generating code: error formatting Go code // Package confluence provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/deepmap/oapi-codegen version v1.11.1-0.20220812203637-fec990c8f823 DO NOT EDIT.
package confluence

import (
...

// ParseUpdateUserPropertyResponse parses an HTTP response from a UpdateUserPropertyWithResponse call
func ParseUpdateUserPropertyResponse(rsp *http.Response) (*UpdateUserPropertyResponse, error) {
...
}


: confluence.go:26991:17: expected selector or type assertion, found '!=' (and 10 more errors)

Then I tried omitting which parts to generate:

% oapi-codegen  -package confluence swagger.v3.json 2>gen.go

It also failed, and gen.go contains:

error generating code: error formatting Go code // Package confluence provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/deepmap/oapi-codegen version v1.11.1-0.20220812203637-fec990c8f823 DO NOT EDIT.
package confluence

import (
...

// GetSwagger returns the Swagger specification corresponding to the generated code
// in this file. The external references of Swagger specification are resolved.
// The logic of resolving external references is tightly connected to "import-mapping" feature.
// Externally referenced files must be embedded in the corresponding golang packages.
// Urls can be supported but this task was out of the scope.
func GetSwagger() (swagger *openapi3.T, err error) {
...
}
: confluence.go:20159:91: expected selector or type assertion, found ')' (and 10 more errors)

jesselang avatar Aug 13 '22 23:08 jesselang

Hey Jesse, thanks for raising this!

Interestingly, I believe this may be because it's not a valid OpenAPI specification.

I've run validation against https://github.com/stoplightio/spectral and https://redocly.com/docs/cli/, and both show a number of errors with the specification 😬

It may be that you need to manually correct those before this will generate successfully

Have you seen if other OpenAPI generators (i.e. in other languages) successfully generate the code for you, or do they also have errors?

jamietanna avatar Aug 16 '22 17:08 jamietanna