Skip to content

Fix addDescription step #627

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

Merged
merged 2 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions compiler/steps/add-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { JsonSpec } from '../model/json-spec'
export default async function addDescription (model: model.Model, jsonSpec: Map<string, JsonSpec>): Promise<model.Model> {
for (const endpoint of model.endpoints) {
if (endpoint.request == null) continue
const requestDefinition = getDefinition(endpoint.request.name)
const requestDefinition = getDefinition(endpoint.request)
const spec = jsonSpec.get(endpoint.name)
assert(spec, `Can't find the json spec for ${endpoint.name}`)

Expand All @@ -40,21 +40,32 @@ export default async function addDescription (model: model.Model, jsonSpec: Map<
})
if (definition?.parts != null) {
const { description } = definition.parts[property.name]
property.description = description
if (typeof description === 'string') {
property.description = property.description ?? description
}
}
}

if (spec.params != null) {
for (const property of requestDefinition.query) {
const param = spec.params[property.name]
if (param != null && typeof param.description === 'string') {
property.description = property.description ?? param.description
}
}
}
}

return model

function getDefinition (name: string): model.Request {
function getDefinition (request: model.TypeName): model.Request {
for (const type of model.types) {
if (type.kind === 'request') {
if (type.name.name === name) {
if (type.name.name === request.name && type.name.namespace === request.namespace) {
return type
}
}
}
throw new Error(`Can't find the request definiton for ${name}`)
throw new Error(`Can't find the request definiton for ${request.namespace}.${request.name}`)
}
}
Loading