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

oav generate-examples generated.json fails to parse x-ms-paths #1006

Open
dargilco opened this issue Oct 11, 2023 · 1 comment
Open

oav generate-examples generated.json fails to parse x-ms-paths #1006

dargilco opened this issue Oct 11, 2023 · 1 comment

Comments

@dargilco
Copy link
Member

dargilco commented Oct 11, 2023

I have a set of TypeSpec files (see this draft PR into azure-rest-api-specs): Azure/azure-rest-api-specs#26146

I run "npx tsp compile" to create an OpenAPI file named "generated.json" from these TypeSpec files.

You can find "generated.json" in the mentioned PR.

I now run "oav generate-examples generated.json". I got a console spew that looks like one example is being generated, but at the end, I got the error below.

{
  message: "fatal error: Cannot read properties of undefined (reading 'post'), {}",
  level: '\x1B[31merror\x1B[39m'
}
fatal error: Cannot read properties of undefined (reading 'post'), {}

Looking at generated.json, I see I have:

"paths": {},
 "x-ms-paths": { ... }

I had to delete the empty "paths" element and rename "x-ms-paths" to "paths" to make the error go away. So I just ended up with:

"paths": {...},

On IM Timothee G. wrote, "Sounds like a bug in oav those paths should be in x-ms-paths it is invalid to have query parameters in paths in swagger which is why x-ms-paths was created". He suggested I open a GitHub issue here on this.

I'm using the latest version of oav (version 3.2.13)

Thanks,

Darren

@mikeharder
Copy link
Member

I believe the fix will be very simple. The following code needs to check for apiPath under both spec.paths and spec["x-ms-paths"]:

oav/lib/generator/util.ts

Lines 114 to 122 in 795eda5

if (!spec.paths[apiPath][methodName]["x-ms-examples"]) {
spec.paths[apiPath][methodName]["x-ms-examples"] = {};
}
if (!(exampleName in spec.paths[apiPath][methodName]["x-ms-examples"])) {
spec.paths[apiPath][methodName]["x-ms-examples"][exampleName] = {
$ref: `./examples/${exampleName}.json`,
};
return spec;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants