Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 0 additions & 2 deletions compiler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import validateRestSpec from './steps/validate-rest-spec'
import addInfo from './steps/add-info'
import addDescription from './steps/add-description'
import validateModel from './steps/validate-model'
import addContentType from './steps/add-content-type'
import readDefinitionValidation from './steps/read-definition-validation'
import addDeprecation from './steps/add-deprecation'
import ExamplesProcessor from './steps/add-examples'
Expand Down Expand Up @@ -73,7 +72,6 @@ compiler
.generateModel()
.step(addInfo)
.step(addDeprecation)
.step(addContentType)
.step(readDefinitionValidation)
.step(validateRestSpec)
.step(addDescription)
Expand Down
17 changes: 13 additions & 4 deletions compiler/src/model/build-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ import {
verifyUniqueness,
parseJsDocTags,
deepEqual,
sourceLocation, sortTypeDefinitions, parseDeprecation
sourceLocation, sortTypeDefinitions, parseDeprecation,
mediaTypeToStringArray
} from './utils'

const jsonSpec = buildJsonSpec()
Expand Down Expand Up @@ -143,11 +144,11 @@ export function compileSpecification (endpointMappings: Record<string, model.End

// Visit all class, interface, enum and type alias definitions
for (const declaration of declarations.classes) {
model.types.push(compileClassOrInterfaceDeclaration(declaration, endpointMappings, declarations.classes))
model.types.push(compileClassOrInterfaceDeclaration(declaration, endpointMappings, declarations.classes, declarations.enums))
}

for (const declaration of declarations.interfaces) {
model.types.push(compileClassOrInterfaceDeclaration(declaration, endpointMappings, declarations.classes))
model.types.push(compileClassOrInterfaceDeclaration(declaration, endpointMappings, declarations.classes, declarations.enums))
}

for (const declaration of declarations.enums) {
Expand All @@ -164,7 +165,7 @@ export function compileSpecification (endpointMappings: Record<string, model.End
return model
}

function compileClassOrInterfaceDeclaration (declaration: ClassDeclaration | InterfaceDeclaration, mappings: Record<string, model.Endpoint>, allClasses: ClassDeclaration[]): model.Request | model.Response | model.Interface {
function compileClassOrInterfaceDeclaration (declaration: ClassDeclaration | InterfaceDeclaration, mappings: Record<string, model.Endpoint>, allClasses: ClassDeclaration[], allEnums: EnumDeclaration[]): model.Request | model.Response | model.Interface | model.Enum {
const name = declaration.getName()
assert(declaration, name != null, 'Anonymous definitions should not exists')

Expand Down Expand Up @@ -234,6 +235,14 @@ function compileClassOrInterfaceDeclaration (declaration: ClassDeclaration | Int
assert(member, property.properties.length > 0, 'There is no need to declare an empty object path_parts, just remove the path_parts declaration.')
pathMember = member
type.path = property.properties
} else if (name === 'request_media_type' || name === 'response_media_type') {
// add those property to requestMediaType and responseMediaType of the endpoint
const mediaType = (member as PropertySignature).getStructure().type as string
if (name === 'request_media_type') {
mapping.requestMediaType = mediaTypeToStringArray(mediaType, allEnums)
} else if (name === 'response_media_type') {
mapping.responseMediaType = mediaTypeToStringArray(mediaType, allEnums)
}
} else if (name === 'query_parameters') {
const property = visitRequestOrResponseProperty(member)
assert(member, property.properties.length > 0, 'There is no need to declare an empty object query_parameters, just remove the query_parameters declaration.')
Expand Down
21 changes: 21 additions & 0 deletions compiler/src/model/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1509,3 +1509,24 @@ export function sortTypeDefinitions (types: model.TypeDefinition[]): void {
return 0
})
}

export function mediaTypeToStringArray (mediaType: string, allEnums: EnumDeclaration[]): string[] {
const mediaTypeEnumName = 'MediaType'
const mediaTypeEnum = allEnums.find(e => e.getName() === mediaTypeEnumName)

// Handle strings separated by a pipe and return multiple media types
let enumTypeList: string[]
if (mediaType.includes('|')) {
enumTypeList = mediaType.split('|').map(mt => mt.trim())
} else {
enumTypeList = [mediaType.trim()]
}

const mediaTypeList: string[] = []
for (const enumType of enumTypeList) {
const memberName = enumType.split('.').pop()
const value = mediaTypeEnum?.getMembers().find(m => m.getName() === memberName)?.getValue() as string
mediaTypeList.push(value)
}
return mediaTypeList
}
44 changes: 0 additions & 44 deletions compiler/src/steps/add-content-type.ts

This file was deleted.

Loading