-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
[typescript-axios] Fix Explode Query Parameters #16898
Conversation
I'll add a spec file and new tests for this shortly |
… into ts-axios-explode
…pi-generator into ts-axios-explode
…pi-generator into ts-axios-explode
… into ts-axios-explode
This change broke enum parameters to me: 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 Downgrading to 7.0.0 solved this issue. |
Ah, that issue only happens when parameter has default value set inside 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;
}
} |
Hi... 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
}
} |
Resolves #16896
This PR modifies the
apiInner
mustache template to properly explode object query parameters and excludes enum query parameters from explosion.PR checklist
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.
master
(upcoming 7.1.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)@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)