cyclosproject / ng-openapi-gen

An OpenAPI 3.0 codegen for Angular
MIT License
403 stars 134 forks source link

Query parameters do not recognize "nullable": true if "required" is true #293

Closed Timkoeln closed 1 year ago

Timkoeln commented 1 year ago

Hello, thank you for the great work!

I just noticed that "nullable: true" is not generated as it should be when "required" is true. Did I miss something?

Here an example API:

openapi: 3.0.1
info:
  title: Test
  version: "1.0"
servers:
  - url: https://localhost/api
paths:
  /test:
    get:
      tags:
        - ExampleGet
      summary: ExampleGet
      operationId: ExampleGet
      parameters:
        - name: filter
          in: query
          required: true
          style: form
          schema:
            type: integer
            nullable: true
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string

Here is what the module generate:

  exampleGet(params: {
    filter: number;
  },
  context?: HttpContext

): Observable<Array<string>> {

    return this.exampleGet$Response(params,context).pipe(
      map((r: StrictHttpResponse<Array<string>>) => r.body as Array<string>)
    );
  }

I would except:

  exampleGet(params: {
    filter: number | null;
  },

Is the behavior correct ?

Timkoeln commented 1 year ago

Hey! Thanks for the quick fix! I noticed that null query params are filtered out in the request builder. Is this expected? I would expect if you explicitly set it to null that the query param is also visible in the url :) It is filtered in line 178 in the requestBuilder.handlebars

luisfpg commented 1 year ago

That's a point: how do you express null in a query parameter? https://url/?param= represents an empty string...

Em sex., 27 de out. de 2023 05:06, Tim Quirl @.***> escreveu:

Hey! Thanks for the quick fix! I noticed that null query params are filtered out in the request builder. Is this expected? I would expect if you explicitly set it to null that the query param is also visible in the url :)

— Reply to this email directly, view it on GitHub https://github.com/cyclosproject/ng-openapi-gen/issues/293#issuecomment-1782481398, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJA76O4CRSNMO4BUMOP5PLYBNTPTAVCNFSM6AAAAAA6CKNCNKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBSGQ4DCMZZHA . You are receiving this because you modified the open/close state.Message ID: @.***>