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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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