json-schema-org / community

A space to discuss community and organisational related things
85 stars 34 forks source link

GSoC: Source Generation Analyzer Powered by Corvus.JsonSchema (.Net) #614

Closed gregsdennis closed 1 month ago

gregsdennis commented 9 months ago

Source Generation Analyzer Powered by Corvus.JsonSchema (.Net)

Brief Description The JSON Schema implementation Corvus.JsonSchema operates by generating source code for types based on a supplied JSON Schema such that the validation constraints present in the schema are rendered in code. An overview of how it works can be found in this video.

Often, different software development teams within a single organization will use different tech stacks to implement their functionality. JSON Schema can help unify these teams by providing a single source of truth for data modelling. The teams will then generate code for the data models.

Extended Description Please see this comment

Expected Outcomes This project is to wrap the code generation functionality of the Corvus library in a .Net source generation analyzer to assist developers by easily generating data models using JSON Schema as a source of truth.

Skills Required

Mentors

Expected Difficulty Medium, if the candidate is familiar with source generators. Hard otherwise.

Expected Time Commitment 175 (minimum, probably)

Expressing interest If you would like to help with this project, please express your interest in a comment below and read through and complete the Qualification Task and be sure to follow the Contributor Guidance.

Kombaiya-MK commented 9 months ago

Hi @gregsdennis , I would like to know more about this issue. Can you please elaborate on what exactly needs to be done?

gregsdennis commented 9 months ago

We're still working some of this out, but off of the top of my head:

Corvus.JsonSchema is currently only a dotnet tool, meaning it can only be used on the command line. This project seeks to add an incremental source generator (recommend watching the video linked above) that can take the code generated by the tool and insert it into a users' source for compilation.

It's likely this can be added to the same Nuget package, though this will need to be researched and confirmed. If it can be, then probably no edits to the exiting code will be needed; just the addition of the analyzer and updating the package accordingly. If not, then there will likely need to be some refactoring of existing code to expose some API. @mwadams can likely provide insights on the existing code.

Ideal user experience

Ideally, it will function similarly to the [JsonSerializable] attribute (and context) already in use by System.Text.Json. I invision something like

[GenerateFromSchema("path/to/schema.json")]
public partial class MyModel;

or even

[assembly:GenerateModelsFromSchema(Schema: "path/to/schema.json", NameSpace: "MyProject.Models")]

You can't put attributes on namespaces, unfortunately, so the target will need to be specified in a string.

I'm not attached to either of these approaches and am open to others, but I think the assembly-level attribute will likely be the most user-friendly.

The attribute itself will be unconditionally source-generated (again, see the video), which will make it available for use immediately upon installing the Nuget package into the target project.

Kombaiya-MK commented 9 months ago

Thank you for your detailed explanation @gregsdennis.I'll explore both options and any other possibilities, and I'll get back to you.

gregsdennis commented 9 months ago

We still need to wait for other interested contributors. There's still some selection process that we have to go through.

Feel free to read up and mull things over, but don't put any effort into this until we're ready to go.

Please join the #gsoc channel in Slack for more info and coordination.

benjagm commented 9 months ago

Thanks a lot for joining JSON Schema org for this edition of GSoC!!

Qualification tasks will be published as comments in the project ideas by Thursday/Friday of this week. In addition I'd like to invite you to a office hours session this thursday 18:30 UTC where we'll present the ideas and the relevant date to consider at this stage of the program.

Please use this link to join the session: 🌐 Zoom 📅 20124-02-29 18:30 UTC

See you there!

gregsdennis commented 9 months ago

Qualifying Task

To qualify for this project, we ask that you perform the tasks below. A .Net solution has been provided to get you started.

In this solution there are three projects: CorvusQualification, ExistingPackage, UserCode.

  1. CorvusQualification does not compile because it uses an attribute that does not exist. Your first task is to update ExistingPackage by adding an incremental source generator that produces the missing attribute. Once the solution compiles this task is complete.

  2. Update ExistingPackage to produce a nuget package that, once installed, allows the user to use ServiceProvider and generates the attribute. Install this package into UserCode and use the attribute as shown in CorvusQualification. JsonSchema.GSoC2024.CorvusQualification.zip

    IMPORTANT UserCode must not contain a project reference to ExistingPackage; it must consume the nuget package. DO NOT UPLOAD YOUR PACKAGE TO NUGET.ORG AS THIS WILL IMPACT OTHER CANDIDATES.

  3. Write a readme for the project describing how a user would install the ExistingPackage nuget package and make use of the attribute.


The completed work will need to be submitted via the GSoC platform. Instructions for this can be found in the contributor guidelines.

mathanraj0601 commented 9 months ago

Hi @gregsdennis , Task is interesting will DM you with solution asap : )

Kombaiya-MK commented 9 months ago

Hi @gregsdennis Could you please provide me with the due date for the task?

mathanraj0601 commented 9 months ago

Hi @gregsdennis,

I recently watched the video on high-performance JSON serialization, where they used a pre-defined class to generate code for a JSON context, effectively avoiding reflection. the generator dealt witth JSON data .

For our qualification task, we need to work with a JSON schema. Could you provide a demo schema.json that guides us in extracting key details, such as property names and types, using a JSON serializer or another NuGet package? This will assist us in generating a well-structured partial class as generated code.

Thank you!

gregsdennis commented 9 months ago

@mathanraj0601 please just do the task as stated. You don't need any more information than what's given.

Once we get into the project, we'll cover more of what's required for that.

gregsdennis commented 9 months ago

@Kombaiya-MK applications to GSoC are due 18 March, so let's shoot for no later than 11 March. That will give Matt and me time to review the tasks and make a selection.

Kombaiya-MK commented 9 months ago

@Kombaiya-MK applications to GSoC are due 18 March, so let's shoot for no later than 11 March. That will give Matt and me time to review the tasks and make a selection.

Sure @gregsdennis

mathanraj0601 commented 9 months ago

@mathanraj0601 please just do the task as stated. You don't need any more information than what's given. Once we get into the project, we'll cover more of what's required for that.

Sure @gregsdennis

gregsdennis commented 8 months ago

Just added a link to the Contributor Guidance in the opening comment. Please read through this and make sure your applications conform to the requirements.

pranayjoshi commented 8 months ago

Hi mentors, My exisitinglibrary compiles successfully, but I keep on getting this issue while compiling the Qualification project. I tried different resources and different solutions but none of them work.

error CS0246: The type or namespace name 'GeneratedAttribute' could not be found (are you missing a using directive or an assembly reference?)

My approach:-

  1. Creating a class under Exisiting Library which is a incremental source generator, I made sure to include [Generator].
  2. Create an execute function which contains the GeneratedAttribute in the form of attribute string.
  3. Then just using context.addsource to execute it.

Someone on the stackoverflow suggest that it might be a different version issue. but I don't think so.

gregsdennis commented 8 months ago

The solution as posted above does not compile. The first part of the task is to add an incremental source generator to ExistingLibrary that creates the attribute, allowing the solution to compile.

This is the task that you have to fulfill. I can't provide direction, only clarification.

The "incremental source generators" video linked in the opening comment gives enough information on how to do this.

pranayjoshi commented 8 months ago

Introductory Questions

Hi everyone, this is Pranay. I am a Full-Stack Developer currently working as a GIS Engineer at the University of Alabama. I am also voluntarily working as a BCI (Brain Computer Interface) Research Assistant, where I am specifically working on creating an SDK between a Bluetooth headset called MUSE.

gregsdennis commented 8 months ago

@pranayjoshi @mathanraj0601 @Kombaiya-MK due to some complications, I've had to update the template solution for the qualification task. Please download the new one (link replaced above). If you've done any work, you should be able to copy it over with some renaming ("ExistingLibrary" -> "ExistingPackage").

mathanraj0601 commented 8 months ago

Sure @gregsdennis

benjagm commented 8 months ago

🚩 IMPORTANT INSTRUCTIONS REGARDING HOW AND WHERE TO SUBMIT YOU APPLICATION 🚩

Please join this discussion in JSON Schema slack to get the last details very important details on how to better submit your application to JSON Schema.

See communication here.

MoMakkawi commented 8 months ago

Hello @gregsdennis , I have knowledge in Roslyn & Source Generators (I worked on many projects, such as my project Organizer-SG) and I contributed to them in .NET. Is it still possible to apply to work on this exciting task?

gregsdennis commented 8 months ago

@MoMakkawi the deadline for applications is 2 Apr. If you can submit before then, you're welcome to. Join #gsoc in slack. Instructions are in the history there.

github-actions[bot] commented 5 months ago

Hello! :wave:

This issue has been automatically marked as stale due to inactivity :sleeping:

It will be closed in 180 days if no further activity occurs. To keep it active, please add a comment with more details.

There can be many reasons why a specific issue has no activity. The most probable cause is a lack of time, not a lack of interest.

Let us figure out together how to push this issue forward. Connect with us through our slack channel : https://json-schema.org/slack

Thank you for your patience :heart:

github-actions[bot] commented 4 months ago

Hello! :wave:

This issue has been automatically marked as stale due to inactivity :sleeping:

It will be closed in 180 days if no further activity occurs. To keep it active, please add a comment with more details.

There can be many reasons why a specific issue has no activity. The most probable cause is a lack of time, not a lack of interest.

Let us figure out together how to push this issue forward. Connect with us through our slack channel : https://json-schema.org/slack

Thank you for your patience :heart:

github-actions[bot] commented 3 months ago

Hello! :wave:

This issue has been automatically marked as stale due to inactivity :sleeping:

It will be closed in 180 days if no further activity occurs. To keep it active, please add a comment with more details.

There can be many reasons why a specific issue has no activity. The most probable cause is a lack of time, not a lack of interest.

Let us figure out together how to push this issue forward. Connect with us through our slack channel : https://json-schema.org/slack

Thank you for your patience :heart: