Skip to content
Open
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
11 changes: 10 additions & 1 deletion 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 @@ -247,6 +248,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)
} else if (name === 'response_media_type') {
mapping.responseMediaType = mediaTypeToStringArray(mediaType)
}
} 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
33 changes: 33 additions & 0 deletions compiler/src/model/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1506,3 +1506,36 @@ export function sortTypeDefinitions (types: model.TypeDefinition[]): void {
return 0
})
}

export function mediaTypeToStringArray (mediaType: string): string[] {
function mediaTypeToString (enumType: string): string {
switch (enumType) {
case 'MediaType.Json':
return 'application/json'
case 'MediaType.Text':
return 'text/plain'
case 'MediaType.Ndjson':
return 'application/x-ndjson'
case 'MediaType.EventStream':
return 'text/event-stream'
case 'MediaType.MapboxVectorTile':
return 'application/vnd.mapbox-vector-tile'
default:
throw new Error(`Unsupported media type: ${enumType}`)
}
}

// 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) {
mediaTypeList.push(mediaTypeToString(enumType))
}
return mediaTypeList
}
44 changes: 0 additions & 44 deletions compiler/src/steps/add-content-type.ts

This file was deleted.

Loading