Skip to content

Commit ce1b3af

Browse files
shawncxmsxichen
andauthored
fix header issue (#667)
Co-authored-by: xichen <[email protected]>
1 parent 27c06e7 commit ce1b3af

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

powershell/plugins/plugin-tweak-m4-model.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ async function tweakModel(state: State): Promise<PwshModel> {
2525
}
2626

2727
function addResponseHeaderSchema(model: CodeModel) {
28-
// 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.
28+
// In remodeler, each operations response headers will has its own scheam. Each header will be schema's property.
29+
// But in m4, if 'schema' is not explicitly defined, even 'headers' is specified, there won't be a schema for headers.
2930
// To keep backward compatiable, we will create headers schema here
3031

3132
model.operationGroups.forEach((group) => {
@@ -34,6 +35,10 @@ function addResponseHeaderSchema(model: CodeModel) {
3435
return;
3536
}
3637
op.responses.forEach((resp) => {
38+
if ((<any>resp).schema) {
39+
return;
40+
}
41+
3742
const headers = resp.protocol.http?.headers as Array<HttpHeader>;
3843
if (headers === undefined) {
3944
return;

powershell/plugins/plugin-tweak-model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ async function tweakModelV2(state: State): Promise<PwshModel> {
188188
if ((response as any).schema.type === SchemaType.Object) {
189189
const respSchema = (response as any).schema as ObjectSchema;
190190
const curHeader = header as any;
191-
const headerKey = curHeader as string;
191+
const headerKey = curHeader.header as string;
192192

193193
respSchema.language.default.hasHeaders = true;
194194

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

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

203203
// mark it that it's a header-only property

0 commit comments

Comments
 (0)