Skip to content

Commit

Permalink
Allow path parameter as enum strings
Browse files Browse the repository at this point in the history
  • Loading branch information
hadashiA committed Dec 21, 2022
1 parent f3cef54 commit ad500b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/buildV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default (openapi: OpenAPIV3.Document) => {
[] as OpenAPIV3.ParameterObject[]
)
],
openapi,
false
)
),
Expand Down
19 changes: 13 additions & 6 deletions src/builderUtils/getDirName.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import { OpenAPIV3 } from 'openapi-types'
import { getPropertyName, schema2value } from './converters'
import { getPropertyName, isRefObject, schema2value } from './converters'
import { resolveSchemasRef } from './resolvers'

export default (text: string, params: OpenAPIV3.ParameterObject[], required: boolean) => {
export default (text: string, params: OpenAPIV3.ParameterObject[], openapi: OpenAPIV3.Document, required: boolean) => {
if (text === '*') return '_any'
if (!/^{/.test(text)) {
return text
}

const valName = text.slice(1, -1)
const schemaVal = schema2value(
params.find(p => p.in === 'path' && p.name === valName)?.schema,
required
)

let schema = params.find(p => p.in === 'path' && p.name === valName)?.schema
if (schema && isRefObject(schema)) {
const referencedSchema = resolveSchemasRef(openapi, schema.$ref)
if (referencedSchema.type === 'string' || referencedSchema.type === 'number') {
schema = referencedSchema
}
}

const schemaVal = schema2value(schema, required)

return `_${getPropertyName(valName)}${
schemaVal && typeof schemaVal.value === 'string' ? `@${schemaVal.value}` : ''
Expand Down

0 comments on commit ad500b5

Please sign in to comment.