Skip to content

Commit

Permalink
fix header issue (#667)
Browse files Browse the repository at this point in the history
Co-authored-by: xichen <[email protected]>
  • Loading branch information
shawncx and msxichen authored Aug 18, 2020
1 parent 27c06e7 commit ce1b3af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion powershell/plugins/plugin-tweak-m4-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ async function tweakModel(state: State): Promise<PwshModel> {
}

function addResponseHeaderSchema(model: CodeModel) {
// In remodler, each operations response headers will has its own scheam. Each header will be schema's property. But in m4, there won't be a schema for headers.
// In remodeler, each operations response headers will has its own scheam. Each header will be schema's property.
// But in m4, if 'schema' is not explicitly defined, even 'headers' is specified, there won't be a schema for headers.
// To keep backward compatiable, we will create headers schema here

model.operationGroups.forEach((group) => {
Expand All @@ -34,6 +35,10 @@ function addResponseHeaderSchema(model: CodeModel) {
return;
}
op.responses.forEach((resp) => {
if ((<any>resp).schema) {
return;
}

const headers = resp.protocol.http?.headers as Array<HttpHeader>;
if (headers === undefined) {
return;
Expand Down
4 changes: 2 additions & 2 deletions powershell/plugins/plugin-tweak-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ async function tweakModelV2(state: State): Promise<PwshModel> {
if ((response as any).schema.type === SchemaType.Object) {
const respSchema = (response as any).schema as ObjectSchema;
const curHeader = header as any;
const headerKey = curHeader as string;
const headerKey = curHeader.header as string;

respSchema.language.default.hasHeaders = true;

Expand All @@ -197,7 +197,7 @@ async function tweakModelV2(state: State): Promise<PwshModel> {
state.message({ Channel: Channel.Debug, Text: `Adding header property '${headerKey}' to model ${respSchema.language.default.name}` });

// create a property for the header value
const newProperty = new Property(headerKey, curHeader.description, curHeader.schema);
const newProperty = new Property(headerKey, curHeader.description || '', curHeader.schema);
newProperty.language.default.required = false;

// mark it that it's a header-only property
Expand Down

0 comments on commit ce1b3af

Please sign in to comment.