Skip to content

Commit

Permalink
Merge pull request #185 from LumaKernel/revert-atmark
Browse files Browse the repository at this point in the history
revert: replaceLeadingAtMark of PR #146
LumaKernel authored Mar 8, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 52db3c8 + a03b993 commit a07a00f
Showing 5 changed files with 6 additions and 25 deletions.
5 changes: 0 additions & 5 deletions aspida.config.js
Original file line number Diff line number Diff line change
@@ -38,10 +38,5 @@ module.exports = [
input: 'samples/array-one-of',
outputEachDir: true,
openapi: { inputFile: 'samples/array-one-of.yml' }
},
{
input: 'samples/path-at-mark',
outputEachDir: true,
openapi: { inputFile: 'samples/path-at-mark.yml', replaceLeadingAtMark: '' }
}
]
7 changes: 2 additions & 5 deletions src/buildTemplate.ts
Original file line number Diff line number Diff line change
@@ -6,14 +6,11 @@ import { Config } from './getConfig'

const isV3 = (openapi: OpenAPI.Document): openapi is OpenAPIV3.Document => 'openapi' in openapi

export default async ({ input, isYaml, replaceLeadingAtMark }: Config) => {
export default async ({ input, isYaml }: Config) => {
const openapi = await parse(input, { parse: { json: !isYaml } })
const docs = isV3(openapi)
? openapi
: await require('swagger2openapi').convertObj(openapi, { direct: true })

return buildV3(
await resolveExternalRefs(docs, typeof input === 'string' ? input : ''),
replaceLeadingAtMark
)
return buildV3(await resolveExternalRefs(docs, typeof input === 'string' ? input : ''))
}
5 changes: 2 additions & 3 deletions src/buildV3.ts
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ const getParamsList = (
params?: (OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject)[]
) => params?.map(p => (isRefObject(p) ? resolveParamsRef(openapi, p.$ref) : p)) || []

export default (openapi: OpenAPIV3.Document, replaceLeadingAtMark: string) => {
export default (openapi: OpenAPIV3.Document) => {
const files: { file: string[]; methods: string }[] = []
const schemas = schemas2Props(openapi.components?.schemas, openapi) || []
const parameters = parameters2Props(openapi.components?.parameters, openapi, false) || []
@@ -56,8 +56,7 @@ export default (openapi: OpenAPIV3.Document, replaceLeadingAtMark: string) => {
[] as OpenAPIV3.ParameterObject[]
)
],
false,
replaceLeadingAtMark
false
)
),
'index'
9 changes: 1 addition & 8 deletions src/builderUtils/getDirName.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import { OpenAPIV3 } from 'openapi-types'
import { getPropertyName, schema2value } from './converters'

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

5 changes: 1 addition & 4 deletions src/getConfig.ts
Original file line number Diff line number Diff line change
@@ -5,14 +5,12 @@ export type Config = Pick<AspidaConfig, 'outputEachDir' | 'outputMode' | 'traili
input: string | OpenAPI.Document
output: string
isYaml: boolean
replaceLeadingAtMark: string
}

export type ConfigFile = AspidaConfig & {
openapi?: {
inputFile: string
yaml?: boolean
replaceLeadingAtMark?: string
outputDir?: string
}
}
@@ -25,8 +23,7 @@ const createConfig = (config: ConfigFile): Config => {
trailingSlash: config.trailingSlash,
outputEachDir: config.outputEachDir,
outputMode: config.outputMode,
isYaml: openapi.yaml ?? !openapi.inputFile.endsWith('.json'),
replaceLeadingAtMark: openapi.replaceLeadingAtMark ?? '@'
isYaml: openapi.yaml ?? !openapi.inputFile.endsWith('.json')
}
}

0 comments on commit a07a00f

Please sign in to comment.