Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix content type header #5075

Merged
merged 3 commits into from
Feb 13, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@autorest/openapi-to-typespec",
"comment": "Fix content type header",
"type": "patch"
}
],
"packageName": "@autorest/openapi-to-typespec"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function generateObjectClientDecorator(typespecObject: TypespecObject) {

definitions.push(generateAugmentedDecorators(typespecObject.name, typespecObject.clientDecorators));

for (const property of typespecObject.properties) {
for (const property of typespecObject.properties ?? []) {
const decorators = generateAugmentedDecorators(
`${typespecObject.name}.${property.name}`,
property.clientDecorators,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { TypespecObject } from "../interfaces";
import { getOptions } from "../options";
import { generateDecorators } from "../utils/decorators";
import { generateDocs } from "../utils/docs";
import { getModelPropertiesDeclarations } from "../utils/model-generation";
Expand Down Expand Up @@ -36,7 +35,7 @@ export function generateObject(typespecObject: TypespecObject) {
}
}

definitions = [...definitions, ...getModelPropertiesDeclarations(typespecObject.properties)];
definitions = [...definitions, ...getModelPropertiesDeclarations(typespecObject.properties ?? [])];
definitions.push("}");

return definitions.join("\n");
Expand Down
15 changes: 9 additions & 6 deletions packages/extensions/openapi-to-typespec/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,12 @@ export interface TypespecVoidType extends TypespecDataType {
name: "_";
}

export type TypespecModel = TypespecTemplateModel | TypespecDataType;
export type TypespecModel = TypespecTemplateModel | TypespecObject;

export interface TypespecTemplateModel extends TypespecDataType {
export interface TypespecTemplateModel extends TypespecDataType, WithAdditionalProperties {
kind: "template";
arguments?: TypespecModel[];
namedArguments?: Record<string, string>; // TO-DO: value is string for now, should be refacted to some object type
additionalProperties?: TypespecParameter[]; // Currently for body purpose
additionalTemplateModel?: string; // Currently for LRO header purpose
}

Expand Down Expand Up @@ -164,6 +163,10 @@ export interface WithSuppressDirective {
suppressionMessage?: string;
}

export interface WithAdditionalProperties {
additionalProperties?: TypespecObjectProperty[];
}

export type TypespecParameterLocation = "path" | "query" | "header" | "body";
export interface TypespecParameter extends TypespecDataType {
kind: "parameter";
Expand Down Expand Up @@ -205,10 +208,10 @@ export interface TypespecAlias {
module?: string;
}

export interface TypespecObject extends TypespecDataType {
export interface TypespecObject extends TypespecDataType, WithAdditionalProperties {
kind: "object";
properties: TypespecObjectProperty[];
parents: string[];
properties?: TypespecObjectProperty[];
parents?: string[];
extendedParents?: string[];
spreadParents?: string[];
decorators?: TypespecDecorator[];
Expand Down
Loading
Loading