Skip to content

[BUG] ERROR! Not handling <code> as Body Parameter at the moment #2580

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

Open
adamdecaf opened this issue Apr 2, 2019 · 21 comments
Open

[BUG] ERROR! Not handling <code> as Body Parameter at the moment #2580

adamdecaf opened this issue Apr 2, 2019 · 21 comments

Comments

@adamdecaf
Copy link
Contributor

Description

I get the following error when trying to generate a Go client:

[main] ERROR o.o.codegen.DefaultCodegen - ERROR! Not handling  class Parameter {
    name: null
    in: null
    description: null
    required: null
    deprecated: null
    allowEmptyValue: null
    style: null
    explode: null
    allowReserved: null
    schema: null
    examples: null
    example: null
    content: null
    $ref: #/components/parameters/idempotencyKey
} as Body Parameter at the moment

This comes about when my root.yaml file contains a paths sub-object with a $ref to an external OpenAPI spec file for a path like:

paths:
  /originators:
    post:
      tags:
        - Originators
      summary: Create a new Originator object
      operationId: addOriginator
      security:
        - bearerAuth: []
        - cookieAuth: []
      parameters:
        - $ref: '#/components/parameters/requestId'
        - $ref: '#/components/parameters/idempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateOriginator'        

  parameters:
    idempotencyKey:
      in: header
      name: X-Idempotency-Key
      description: Idempotent key in the header which expires after 24 hours. These strings should contain enough entropy for to not collide with each other in your requests.
      example: a4f88150
      required: false
      schema:
        type: string
openapi-generator version

4.0.0-beta2

Steps to reproduce
OPENAPI_GENERATOR_VERSION=4.0.0-beta2 ./openapi-generator generate -i openapi.yaml -g go -o ./client
Suggest a fix

Looking at the relevant source code this path is simply commented out (and has been for quite some time), so I assume there's a refactor needed?

I'm willing to offer a patch which fixes this, but I'm unsure of the history or what all would need to be refactored. Any advice? I'll contribute a reproducible local test as part of the PR.

@auto-labeler
Copy link

auto-labeler bot commented Apr 2, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@wing328
Copy link
Member

wing328 commented Apr 3, 2019

Thanks for reporting the issue and offering help to fix it.

Can you share the full spec via gist.github.com so that we can more easily reproduce the issue?

@adamdecaf
Copy link
Contributor Author

adamdecaf commented Apr 4, 2019

Sure thing, here's the yaml files and output.

issue-2580.yaml:

openapi: 3.0.2
info:
  version: v1
  title: Test API

tags:
  - name: Test
    description: TODO

paths:
  /v1/foo:
    $ref: './issue-2580-part2.yaml#/paths/~1foo'

issue-2580-part2.yaml:

openapi: 3.0.2
info:
  version: v1
  title: Test API

tags:
  - name: Test
    description: TODO

paths:
  /foo:
    post:
      tags:
        - Test
      summary: Random endpoint
      operationId: foo
      parameters:
        - $ref: '#/components/parameters/XUserIdHeader'
      responses:
        '200':
          description: Service is running properly

components:
  parameters:
    XUserIdHeader:
      in: header
      name: X-User-Id
      description: Moov User ID header, required in all requests
      example: e3cdf999
      schema:
        type: string
      required: true

Output:

$ make 
OPENAPI_GENERATOR_VERSION=4.0.0-beta3 ./openapi-generator generate -i issue-2580.yaml -g go -o ./client
[main] WARN  o.o.c.ignore.CodegenIgnoreProcessor - Output directory does not exist, or is inaccessible. No file (.openapi-generator-ignore) will be evaluated.
[main] INFO  o.o.c.languages.AbstractGoCodegen - Environment variable GO_POST_PROCESS_FILE not defined so Go code may not be properly formatted. To define it, try `export GO_POST_PROCESS_FILE="/usr/local/bin/gofmt -w"` (Linux/Mac)
[main] INFO  o.o.c.languages.AbstractGoCodegen - NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).
[main] WARN  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
[main] WARN  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
[main] ERROR o.o.codegen.DefaultCodegen - ERROR! Not handling  class Parameter {
    name: null
    in: null
    description: null
    required: null
    deprecated: null
    allowEmptyValue: null
    style: null
    explode: null
    allowReserved: null
    schema: null
    examples: null
    example: null
    content: null
    $ref: #/components/parameters/XUserIdHeader
} as Body Parameter at the moment
[main] ERROR o.o.codegen.DefaultCodegen - ERROR! Not handling  class Parameter {
    name: null
    in: null
    description: null
    required: null
    deprecated: null
    allowEmptyValue: null
    style: null
    explode: null
    allowReserved: null
    schema: null
    examples: null
    example: null
    content: null
    $ref: #/components/parameters/XUserIdHeader
} as Body Parameter at the moment
[main] WARN  o.o.codegen.DefaultCodegen - Unknown parameter type: null
[main] WARN  o.o.codegen.DefaultCodegen - Parameter name not defined properly. Default to UNKNOWN_PARAMETER_NAME
[main] WARN  o.o.codegen.DefaultCodegen - Unknown parameter type null for null
Exception in thread "main" java.lang.RuntimeException: Could not generate api file for 'Test'
	at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:654)
	at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:902)
	at org.openapitools.codegen.cmd.Generate.run(Generate.java:368)
	at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:60)
Caused by: java.lang.NullPointerException
	at org.openapitools.codegen.languages.AbstractGoCodegen.postProcessOperationsWithModels(AbstractGoCodegen.java:402)
	at org.openapitools.codegen.DefaultGenerator.processOperations(DefaultGenerator.java:1116)
	at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:540)
	... 3 more
make: *** [client] Error 1

Note: Running the generator against issue-2580-part2.yaml runs fine, so it's only with issue-2580.yaml that I'm seeing this failure.

@adamdecaf
Copy link
Contributor Author

Is there any advice for how I should go about fixing this? I can try to work through the commented out code, but it seems pretty old. Thanks - cc @wing328

@adamdecaf
Copy link
Contributor Author

If I move the $ref parameter inline with the spec everything generates fine. I'll do that to solve my build, but is there a way to let $ref work?

openapi: 3.0.2
info:
  version: v1
  title: Test API

servers:
  - url: https://api.moov.io
    description: Production server

tags:
  - name: Test
    description: TODO

paths:
  /v1/foo:
    $ref: './issue-2580-part2.yaml#/paths/~1foo'
openapi: 3.0.2
info:
  version: v1
  title: Test API

tags:
  - name: Test
    description: TODO

paths:
  /foo:
    post:
      tags:
        - Test
      summary: Random endpoint
      operationId: foo
      parameters:
        - name: XUserIdHeader
          in: header
          name: X-User-Id
          description: Moov User ID header, required in all requests
          schema:
            type: string
            example: e3cdf999
          required: true
      responses:
        '200':
          description: Service is running properly

@lacksfish
Copy link

Experience the same issue. Results are messy generated code with method parameter named UNKNOWN_PARAMETER_NAME and UNKNOWN_PARAMETER_NAME_2 for further parameters ...

Is this because of providing multiple parameters for the same path with multiple - ref:'s ?

Confusing bug..

@lacksfish
Copy link

lacksfish commented May 8, 2019

This is the error log, it shows up on a few paths (pet_name is only a substitute)

...
[main] ERROR o.o.codegen.DefaultCodegen - ERROR! Not handling  class Parameter {
    name: null
    in: null
    description: null
    required: null
    deprecated: null
    allowEmptyValue: null
    style: null
    explode: null
    allowReserved: null
    schema: null
    examples: null
    example: null
    content: null
    $ref: ./spec.addons.yaml#/parameters/pet_name
} as Body Parameter at the moment
[main] WARN  o.o.codegen.DefaultCodegen - Unknown parameter type: null
[main] WARN  o.o.codegen.DefaultCodegen - Parameter name not defined properly. Default to UNKNOWN_PARAMETER_NAME
[main] WARN  o.o.codegen.DefaultCodegen - Unknown parameter type null for null
...

@lacksfish
Copy link

FWIW, the error is repetitive for certain parameters throughout the log, I suppose for every time it is referred.

@lacksfish
Copy link

An example path that has this issue would be:

/private/that_err_endpoint:
    get:
      examples:
        jsonObject:
          externalValue: examples/private/that_err_endpoint.request.json
      parameters:
      - $ref: 'spec.addons.yaml#/parameters/pet_name'
      - $ref: 'spec.addons.yaml#/parameters/optional_param1'
      - $ref: 'spec.addons.yaml#/parameters/optional_param2'
      responses:
        '200':
          content:
            application/json:
              examples:
                jsonObject:
                  externalValue: examples/private/that_err_endpoint.response.json
              schema:
                $ref: 'spec.addons.yaml#/components/responses/that_err_endpoint_response'
      tags:
      - tag1
      - tag2

And the pet_name param in spec.addons.yaml would look like this:

parameters:
  pet_name:
    description: Name of the pet
    in: query
    name: pet_name
    required: true
    schema:
      example: "Catdog"
      type: string

@agrizzli
Copy link

I had an error with same output like provided by adamdecaf and others, but only because of a typo in $ref path to parameter. I used only one file with components/parameters defined there in. So correct references get lost somewhere due to inclusion of other files, I guess. Maybe it helps some how.

@danielbartsch
Copy link

danielbartsch commented Jan 27, 2021

I have the same error with a much smaller yaml, and only within one file
(this happens when trying to generate a typescript client btw):

swagger: '2.0'
info:
  description: Description
  title: Title
paths:
  /:
    get:
      parameters:
        - $ref: '#/parameters/Language'
      responses:
        200:
          description: Description
          schema:
            type: file
parameters:
  Language:
    $ref: '#/definitions/LanguageEnum'
definitions:
  LanguageEnum:
    type: string
    enum:
      - de-DE
      - en-US
  Simple:
    type: object
    properties:
      language:
        $ref: '#/definitions/LanguageEnum'

running validate doesn't say anything bad (except unused models)
running generate then yields what's defined in the issue
(Twice for some reason)

[main] ERROR o.o.codegen.DefaultCodegen - ERROR! Not handling  class Parameter {
    name: null
    in: null
    description: null
    required: null
    deprecated: null
    allowEmptyValue: null
    style: null
    explode: null
    allowReserved: null
    schema: null
    examples: null
    example: null
    content: null
    $ref: #/definitions/LanguageEnum
} as Body Parameter at the moment
[main] ERROR o.o.codegen.DefaultCodegen - ERROR! Not handling  class Parameter {
    name: null
    in: null
    description: null
    required: null
    deprecated: null
    allowEmptyValue: null
    style: null
    explode: null
    allowReserved: null
    schema: null
    examples: null
    example: null
    content: null
    $ref: #/definitions/LanguageEnum
} as Body Parameter at the moment

The command I use to generate:

openapi-generator-cli generate \
   -g typescript-axios \
   -i <path_to_file_above> \
   -o <some_output_path>

@simPod
Copy link
Contributor

simPod commented Apr 7, 2021

I had the same issue and am running exactly the same command as @danielbartsch

I validated my schema against https://editor.swagger.io/ and fixed errors it had shown (was missing schema for params in my case).

Fix those and you'll be fine.

openapi-generator-cli validate did not catch those.

@sankouski-dzmitry
Copy link

sankouski-dzmitry commented Nov 19, 2021

I faced similar issue when generating jira cloud api client. Generated code is broken, with UNKNOWN_PARAM_NAME instead of body. It's reproduced with java and go languages(maybe others too, but not tested). swagger-codegen-cli generates valid code.

Details:

  • openapi generator version: 5.3.0
  • jira openapi spec file
  • validate command java -jar /opt/openapi/openapi-generator-cli-5.3.0.jar validate -i https://developer.atlassian.com/cloud/jira/platform/swagger-v3.v3.json output:
Validating spec (https://developer.atlassian.com/cloud/jira/platform/swagger-v3.v3.json)
Warnings: 
        - Unused model: RichText
        - Unused model: AttachmentArchive
        - Unused model: PaginatedResponseComment
        - Unused model: IconBean

[info] Spec has 4 recommendation(s).
  • generate command: java -jar /opt/openapi/openapi-generator-cli-5.3.0.jar generate -i https://developer.atlassian.com/cloud/jira/platform/swagger-v3.v3.json --api-package com.atlassian.jira.rest.client.api --invoker-package com.atlassian.jira.rest.client.invoker --model-package com.atlassian.jira.rest.client.model --group-id com.atlassian.jira.rest --artifact-id jira-cloud-api -g go -o /tmp/jira_go
  • grep -R UNKNOWN_PARAM_NAME /tmp/jira_go output:
/tmp/jira_go/api_user_properties.go:    UNKNOWN_PARAM_NAME *
/tmp/jira_go/api_user_properties.go:func (r ApiSetUserPropertyRequest) UNKNOWN_PARAM_NAME(UNKNOWN_PARAM_NAME ) ApiSetUserPropertyRequest {
/tmp/jira_go/api_user_properties.go:    r.UNKNOWN_PARAM_NAME = &UNKNOWN_PARAM_NAME
/tmp/jira_go/api_user_properties.go:    if r.UNKNOWN_PARAM_NAME == nil {.........

@simllll
Copy link

simllll commented Nov 24, 2021

Same for typescript-axios client.

editYoutubeId(companyId: string, UNKNOWN_PARAM_NAME: , options?: any): AxiosPromise<IAPICompany> {
            return localVarFp.editYoutubeId(companyId, UNKNOWN_PARAM_NAME, options).then((request) => request(axios, basePath));
        },

@equalspeterd
Copy link

FWIW, you can also reproduce this with the openapi-yaml generator. While the go label might be helpful, it really is an issue in the core default generator.

@Francoois
Copy link

I had the same issue and am running exactly the same command as @danielbartsch

I validated my schema against https://editor.swagger.io/ and fixed errors it had shown (was missing schema for params in my case).

Fix those and you'll be fine.

openapi-generator-cli validate did not catch those.

Saved my day, thank you !

@ColeMurray
Copy link

Ran into the same error. In my case, I had invalid syntax in one of my objects

MyObject:
  type: object
  properties:
     val:
         type: string
         required: false

Where the required false is invalid syntax.

@rafael-as-martins
Copy link

rafael-as-martins commented Nov 28, 2022

How do we stand regarding this issue, is this an open bug?

I'm currently facing the reported issue. Where by having referenced header parameters results into a:

[main] ERROR o.o.codegen.DefaultCodegen - Not handling class Parameter {
    name: Request-ID
    in: header
    description: null
    required: null
    deprecated: null
    allowEmptyValue: null
    style: null
    explode: null
    allowReserved: null
    schema: null
    examples: null
    example: null
    content: null
    $ref: null
} as Body Parameter at the moment
[main] WARN  o.o.codegen.DefaultCodegen - Parameter name not defined properly. Default to UNKNOWN_PARAMETER_NAME

Currently using openapi-generator-cli@5.4.0, but 2.3.9 also results into the same issue.
Swagger editor doesn't highlight any issue with the swagger file.

@miken32
Copy link

miken32 commented Nov 22, 2023

Just to confirm, this is still an issue...

@kino90
Copy link

kino90 commented Nov 30, 2023

Same problem, using typescript-axios generator

@vfouqueron
Copy link

vfouqueron commented Jan 5, 2024

I had the same issue, it is caused by $ref containing '{' and '}' character

I opened an issue on swagger-parser repository swagger-api/swagger-parser#2033

As a workaround, you can try to replace these by %7B and %7D which will be well interpreted by URI

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

No branches or pull requests