Skip to content

Commit

Permalink
fix: convert names that begin with a number
Browse files Browse the repository at this point in the history
  • Loading branch information
solufa committed May 15, 2021
1 parent 65b919c commit 9b2dcfa
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions samples/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2149,7 +2149,7 @@
{
"type": "object",
"required": ["token"],
"properties": { "settings": { "$ref": "#/components/schemas/UserSettings" } }
"properties": { "settings": { "$ref": "#/components/schemas/200-UserSettings" } }
}
]
}
Expand Down Expand Up @@ -2381,7 +2381,7 @@
"type": "string",
"example": "bc402f28c60255f6af5057434587e5a41e71afb0"
},
"settings": { "$ref": "#/components/schemas/UserSettings" }
"settings": { "$ref": "#/components/schemas/200-UserSettings" }
}
}
]
Expand Down Expand Up @@ -3247,7 +3247,7 @@
"url": { "type": "string", "format": "url" }
}
},
"UserSettings": {
"200-UserSettings": {
"required": ["isAppLocked"],
"properties": { "isAppLocked": { "type": "boolean" } }
},
Expand Down
2 changes: 1 addition & 1 deletion samples/openapi/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export type UserInfo = {
url: string
}

export type UserSettings = {
export type $200_UserSettings = {
isAppLocked: boolean
}

Expand Down
2 changes: 1 addition & 1 deletion samples/openapi/api/v3/login/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type Methods = {
/** OK */
resBody: Types.UserInfo & {
token: string
settings?: Types.UserSettings
settings?: Types.$200_UserSettings
}

reqBody: {
Expand Down
2 changes: 1 addition & 1 deletion samples/openapi/api/v3/me/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type Methods = {

/** OK */
resBody: Types.UserInfo & {
settings?: Types.UserSettings
settings?: Types.$200_UserSettings
}
}
}
4 changes: 3 additions & 1 deletion src/builderUtils/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { OpenAPIV3 } from 'openapi-types'
import { Prop, PropValue } from './props2String'

export const defKey2defName = (key: string) =>
`${key[0].toUpperCase()}${key.slice(1).replace(/[^a-zA-Z0-9$_]/g, '_')}`
`${key[0].replace(/^([^a-zA-Z$_])$/, '$$$1').toUpperCase()}${key
.slice(1)
.replace(/[^a-zA-Z0-9$_]/g, '_')}`

export const $ref2TypeName = (ref: string) => {
const [, , , typeName, , propName] = ref.split('/')
Expand Down

0 comments on commit 9b2dcfa

Please sign in to comment.