Skip to content
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

[typescript-axios] Fix Explode Query Parameters #16898

Merged
merged 17 commits into from
Nov 1, 2023

Conversation

ckoegel
Copy link
Contributor

@ckoegel ckoegel commented Oct 24, 2023

Resolves #16896
This PR modifies the apiInner mustache template to properly explode object query parameters and excludes enum query parameters from explosion.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (upcoming 7.1.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02) @davidgamero (2022/03) @mkusaka (2022/04)

@ckoegel
Copy link
Contributor Author

ckoegel commented Oct 24, 2023

I'll add a spec file and new tests for this shortly

@ckoegel ckoegel marked this pull request as ready for review October 31, 2023 15:30
@wing328 wing328 merged commit c2a4163 into OpenAPITools:master Nov 1, 2023
19 checks passed
@ckoegel ckoegel deleted the ts-axios-explode branch November 1, 2023 13:11
@Naktibalda
Copy link
Contributor

This change broke enum parameters to me:
I have this enum:

    SortOrderEnum:
      type: string
      enum:
        - asc
        - desc

Which is used in parameters schema:

      parameters:
        - schema:
            allOf:
              - $ref: "#/components/schemas/SortOrderEnum"
              - default: asc
          required: false
          name: ranking
          in: query

After upgrading to 7.1.0 generated code was changed from

if (ranking !== undefined) {
  localVarQueryParameter['ranking'] = ranking;
}

to

if (ranking !== undefined) {
  for (const [key, value] of Object.entries(ranking)) {
    localVarQueryParameter[key] = value;
  }
} 

It generates URIs with ?0=d&1=e&2=s&3=c .

Downgrading to 7.0.0 solved this issue.
I will raise a new issue.

@Naktibalda
Copy link
Contributor

Ah, that issue only happens when parameter has default value set inside allOf.

Bigger example:

- schema:
    $ref: "#/components/schemas/SortOrderEnum"
    required: false
    name: score
    in: query
- schema:
    allOf:
        - $ref: "#/components/schemas/SortOrderEnum"
        - default: desc
    required: false
    name: createdAt
    in: query

Generates this code:

if (score !== undefined) {
    localVarQueryParameter['score'] = score;
}

if (createdAt !== undefined) {
    for (const [key, value] of Object.entries(createdAt)) {
        localVarQueryParameter[key] = value;
    }
}

@PRTGC
Copy link

PRTGC commented Dec 26, 2023

Hi...
I have this issue as well...
The Example does not show up either

Neither :

    status: # $ref: '#/components/schemas/status'
      default: NOK
      example: NOK
      enum:
      - OK
      - NOK
      x-enum-descriptions:
        - "Ok"
        - "Not Ok"
    DoqlUnmatchedCount:
      type: object
      properties:
        unmatched_count:
          type: integer
          example: "709"
          default: 0
          x-label: Unmatched Discovery records
          x-units: recs
        api_status:
            $ref: '#/components/schemas/status'
      required:
        - unmatched_count
        - api_status
 

Nor this

    status: # $ref: '#/components/schemas/status'
      enum:
      - OK
      - NOK
      x-enum-descriptions:
        - "Ok"
        - "Not Ok"
    DoqlUnmatchedCount:
      type: object
      properties:
        unmatched_count:
          type: integer
          example: "709"
          default: 0
          x-label: Unmatched Discovery records
          x-units: recs
        api_status:
          allOf:
            - $ref: '#/components/schemas/status'
            - default: NOC
            - example: NOK
      required:
        - unmatched_count
        - api_status
#[automatically_derived]
impl Default for {{{classname}}} {
    fn default() -> Self {// XEnum1:
/*  {{{.}}}   */
// Default: "{{defaultValue}}"
// Example: "{{example}}"
{{#defaultValue}}
    Self::{{defaultValue}}{{#vendorExtensions.x-add-enumValueSuffix}}{{{.}}}{{/vendorExtensions.x-add-enumValueSuffix}}
{{/defaultValue}}{{^defaultValue}}{{#allowableValues}}
        {{#enumVars}}{{#-first}}Self::{{name}}{{#vendorExtensions.x-add-enumValueSuffix}}{{{.}}}{{/vendorExtensions.x-add-enumValueSuffix}}{{/-first}}{{/enumVars}}{{/allowableValues}}
        // Self::_EUninitialized{{#vendorExtensions.x-add-enumValueSuffix}}{{{.}}}{{/vendorExtensions.x-add-enumValueSuffix}}
        {{/defaultValue}}
    }
}

Produce the correct thing:

#[automatically_derived]
impl Default for Status {
    fn default() -> Self {// XEnum1:
/*  CodegenModel{name='status', parent='null', parentSchema='null', interfaces=null, interfaceModels=[], allParents=null, parentModel=null, children=[], anyOf=[], oneOf=[], allOf=[], classname='Status', title='null', description='null', classVarName='status', modelJson='{
  "type" : "string",
  "example" : "NOK",
  "default" : "NOK",
  "enum" : [ "OK", "NOK" ],
  "x-enum-descriptions" : [ "Ok", "Not Ok" ]
}', dataType='String', xmlPrefix='null', xmlNamespace='null', xmlName='null', classFilename='status', unescapedDescription='null', discriminator=null, defaultValue='null', arrayModelType='null', isAlias=false, isString=true, isInteger=false, isShort=false, isLong=false, isUnboundedInteger=false, isBoolean=false, isNumber=false, isNumeric=false, isFloat=false, isDouble=false, isDate=false, isDateTime=false, vars=[], allVars=[], nonNullableVars=[], requiredVars=[], optionalVars=[], readOnlyVars=[], readWriteVars=[], parentVars=[], allowableValues={values=[OK, NOK], enumVars=[{name=Ok, isString=true, enumDescription=Ok, value=OK}, {name=Nok, isString=true, enumDescription=Not Ok, value=NOK}]}, mandatory=[], allMandatory=[], imports=[], hasVars=false, emptyVars=false, hasMoreModels=false, hasEnums=false, isEnum=true, isNullable=false, hasRequired=false, hasOptional=false, isArray=false, hasChildren=false, isMap=false, isDeprecated=false, hasOnlyReadOnly=true, externalDocumentation=null, vendorExtensions={x-enum-descriptions=[Ok, Not Ok]}, additionalPropertiesType='null', isAdditionalPropertiesTrue='false', maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, maxItems=null, minItems=null, maxLength=null, minLength=null, exclusiveMinimum=false, exclusiveMaximum=false, minimum='null', maximum='null', pattern='null', multipleOf='null', items='null', additionalProperties='null', isModel='false', isNull='false, hasValidation='false, getAdditionalPropertiesIsAnyType=false, getHasDiscriminatorWithNonEmptyMapping=false, getIsAnyType=false, composedSchemas=null, hasMultipleTypes=false, isDecimal=false, isUUID=false, isURI=false, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=null, dependentRequired=null, contains=null}   */
// Default: ""
// Example: ""

        Self::Ok
        // Self::_EUninitialized
    }
}

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

Successfully merging this pull request may close these issues.

[BUG] [typescript-axios] Handling of explode query causes TS error and breaks enums
4 participants