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

Return $metadata resource as odata + openapi spec #528

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fisehara
Copy link
Contributor

@fisehara fisehara commented Feb 24, 2022

Returning odata and openapi specs in json format.
Specs are scoped to the request permissions.
Different users (roles) will receive different metadata endpoints
and resources.

Change-type: minor
See: https://jel.ly.fish/thread-93132f4a-1885-43c4-ac8d-1c190052e7d9
See: https://jel.ly.fish/thread-4245cd32-8b76-4c1a-a195-c8615c41b321
Signed-off-by: Harald Fischer harald@balena.io

@fisehara fisehara force-pushed the odata-metadata-json branch 4 times, most recently from 3ce2bb1 to efc396d Compare March 2, 2022 23:00
@fisehara fisehara changed the title odata-metadata-json endpoint Return $metadata resource as odata + openapi spec Mar 2, 2022
@fisehara fisehara requested review from Page- and JSReds March 2, 2022 23:00
@fisehara fisehara force-pushed the odata-metadata-json branch 3 times, most recently from d178dd7 to 1593dfb Compare March 4, 2022 15:13
@fisehara fisehara force-pushed the odata-metadata-json branch 2 times, most recently from 08ed3e9 to 79a815c Compare March 8, 2022 18:50
@fisehara fisehara force-pushed the odata-metadata-json branch 2 times, most recently from 7e03cea to 45841e6 Compare March 21, 2022 08:25
@fisehara fisehara force-pushed the odata-metadata-json branch 2 times, most recently from 54bcbfc to b39bec1 Compare July 20, 2022 16:59
@fisehara
Copy link
Contributor Author

FYI @vipulgupta2048

@fisehara fisehara force-pushed the odata-metadata-json branch 3 times, most recently from ffadb18 to 6e86ce9 Compare August 10, 2022 20:05
@fisehara fisehara changed the title Return $metadata resource as odata + openapi spec DRAFT: Return $metadata resource as odata + openapi spec Aug 10, 2022
@fisehara fisehara force-pushed the odata-metadata-json branch 2 times, most recently from dbd8d4b to f70416c Compare August 18, 2022 20:33
@fisehara fisehara changed the title DRAFT: Return $metadata resource as odata + openapi spec Return $metadata resource as odata + openapi spec Aug 24, 2022
@fisehara fisehara requested a review from thgreasi August 24, 2022 13:01
@@ -312,7 +312,7 @@ const namespaceRelationships = (
});
};

type PermissionLookup = Dictionary<true | string[]>;
export type PermissionLookup = _.Dictionary<true | string[]>;
Copy link

@JSReds JSReds Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity, what is the difference between lodash Dictionary and pinejs-client-core Dictionary ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JSReds good catch. thx! This is a mistake. I only needed to export the PermissionLookup and not change the type.
Fixed to not use lodash dictionary.

@fisehara fisehara requested a review from JSReds August 26, 2022 18:31
@fisehara fisehara force-pushed the odata-metadata-json branch 2 times, most recently from 5ea99ed to 5d1f441 Compare November 8, 2022 17:28
@fisehara fisehara force-pushed the odata-metadata-json branch 3 times, most recently from da239da to 9b62b0e Compare January 2, 2023 14:58
@fisehara fisehara marked this pull request as draft January 27, 2023 17:47
@fisehara fisehara force-pushed the odata-metadata-json branch 3 times, most recently from e2841ca to 83b4198 Compare June 5, 2023 11:06
@shaunco
Copy link

shaunco commented Sep 20, 2023

@fisehara - would love to see this merged. I just set out to build a golang API wrapper for Balena and ran into the lack of $metadata pretty quickly. Exposing the $metadata endpoint would allow OData client generators in a bunch of languages produce clients.

@@ -1728,6 +1754,8 @@ const respondGet = async (
}
};

// paths./any/.get.responses.200.content.application/json.schema.d
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this about?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noise ;) Deleted.

* Used oasis translator generates openapi according to v4 spec (`value: `)
*/

Object.keys(openAPIJson.paths).forEach((i) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer a for-of in general:

Suggested change
Object.keys(openAPIJson.paths).forEach((i) => {
for (const i of Object.keys(openAPIJson.paths)) {

Comment on lines 42 to 65
if (
openAPIJson?.paths[i]?.get?.responses?.['200']?.content?.[
'application/json'
]?.schema?.properties?.value
) {
openAPIJson.paths[i].get.responses['200'].content[
'application/json'
].schema.properties['d'] =
openAPIJson.paths[i].get.responses['200'].content[
'application/json'
].schema.properties.value;
delete openAPIJson.paths[i].get.responses['200'].content[
'application/json'
].schema.properties.value;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the pattern of:

Suggested change
if (
openAPIJson?.paths[i]?.get?.responses?.['200']?.content?.[
'application/json'
]?.schema?.properties?.value
) {
openAPIJson.paths[i].get.responses['200'].content[
'application/json'
].schema.properties['d'] =
openAPIJson.paths[i].get.responses['200'].content[
'application/json'
].schema.properties.value;
delete openAPIJson.paths[i].get.responses['200'].content[
'application/json'
].schema.properties.value;
}
const properties = openAPIJson?.paths[i]?.get?.responses?.['200']?.content?.[
'application/json'
]?.schema?.properties
if (properties?.value) {
properties['d'] = properties.value;
delete properties.value;
}

@fisehara fisehara force-pushed the odata-metadata-json branch 9 times, most recently from 78f5a7e to 78b8394 Compare November 9, 2023 23:21
@fisehara fisehara force-pushed the odata-metadata-json branch 4 times, most recently from 584853e to 25d92ed Compare January 24, 2024 13:04
Returning odata and openapi specs in json format.
Specs are scoped to the request permissions.
Different users (roles) will receive different metadata endpoints
and resources.

Change-type: minor
Signed-off-by: Harald Fischer <harald@balena.io>
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

Successfully merging this pull request may close these issues.

None yet

4 participants