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

Considering rendering json objects as references #40

Open
2 tasks
bruno-f-cruz opened this issue Jun 7, 2024 · 1 comment
Open
2 tasks

Considering rendering json objects as references #40

bruno-f-cruz opened this issue Jun 7, 2024 · 1 comment

Comments

@bruno-f-cruz
Copy link
Contributor

Given a schema, it would be very interesting to allow certain objects from being rendered to the final csharp code. This could allow users to pass objects that, as long as share the same name with an already defined class, could be used as a reference.

To make this work we would need:

  • A custom tag to allow the generator to skip the rendering of this objects (similar to x-Abstract)
  • A way to inject using statements at the top of the generated field
@bruno-f-cruz
Copy link
Contributor Author

bruno-f-cruz commented Jun 11, 2024

After looking into "standard" (use this word rather generously) extension tags for OpenAPI and those available to NJsonSchema schema (https://github.com/RicoSuter/NJsonSchema/blob/083501d3594f6a4af8ae5bee0a81b50b4900a763/src/NJsonSchema/JsonSchema.cs#L525), I don't believe we should co-opt any of the available tags.

The alternative is to start keeping a record of sgen-related extension tags. This strategy is in fact covered by the OpenAPI spec, as well as adopted by several other tools.

I thus propose to use the x-sgen-namespace tag. This tag would be of type string and would be used to append a namespace to the class. On automatic code creation, if a class is a namespace, the generator would only create references but not the class itself (nor its constructor). The generator could also leverage all the unique namespaces in the schema and append them to the top of the file as using statements. To prevent name clashing, we could also just render the full namespace.class name in the generated file.

Since NJsonSchema does not have hooks to other flags, we will likely need to add a preprocessing step to the schema ingestion.

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

1 participant