Extending the Appsettings-schema.json
# help-with-umbraco
c
Hi friends! Does anyone know if it's possible to (easily?) automatically extend the default provided appsettings-schema.json by Umbraco from an Umbraco package POV? Being able to ship an additional schema file isn't an issue, but it seems like I'll also need to be able to add an entry to the default appsettings-schema.json for it to be referenced đŸ¤”
p
When in doubt, check what uSync does: https://github.com/KevinJump/uSync/pull/447
Atleast, I think that is doing what you want to do here
Think you mostly want to check out this project: https://github.com/KevinJump/uSync/tree/v12/main/uSync.SchemaGenerator
c
That's exactly what I did haha, though I thought that only created the actual schema file, not the reference to it! Will have a closer look though, thanks Patrick! đŸ˜„
p
Would love to hear if it actually works đŸ˜› Then I can also add it to my packages
c
To ping or not to ping Kevin, that's the question đŸ˜‚
Aah yes @Patrick de Mooij! Umbraco has a Targets buildTransitive that adds the Json schema references, and uSync adds on to that! https://github.com/umbraco/Umbraco-CMS/blob/86697ff137ab6a35d5279f4c1d6991093e1bb54c/src/Umbraco.Cms.Targets/buildTransitive/Umbraco.Cms.Targets.targets#L19C1-L19C1
m
@Corné Hoskam have you considered a separate settings file with a separate schema?
this way you'd keep your package settings in a separate clean file
you'd have to load it in the startup next to the appsettings.json
c
While possible, I feel like the best practise would be to stick with the 'default' / well known way of handling appsettings, where you stick with one appsettings.json file and have specific overrides per environment. This method would also require no additional loading of a json file. What would be the pro's and con's of going for a seperate settings file approach?
m
Pros: - you are not depedant on someone else's appsettings-schema.json - you don't have to mess with someone else's appsettings-schema.json - cleaner settings file with settings specific to your package (which also means cleaner appsettings.json files) - if you schema changes with a new version of the package, it's easier to update Cons - Load your own settings file including the environment variants (if applicable)
In general I'd say it gives you more freedom of doing whatever you want with your schema and settings file
in any case, whatever you choose, just don't add your schema to the schema store to avoid issues like this: https://github.com/umbraco/Umbraco-CMS/issues/14131
k
Hi yeah I am away from my desk, but we have a tool in the usync project for creating a schema file and Umbraco (v11+) has the feature where you add the targets and then you have your schema injected into the default one. Way easier (and safer) them messing about with the schema files yourself
(The tool Creates the schema from options class, it should be relatively easy to adapt that for your own classes. And then it is ran as a built step)
c
Thank you Miguel and Kevin for the detailed information! I'll definitely be considering the options and looking at what uSync has done! đŸ™Œ
Managed to get the inclusion of a provided schema file working! đŸ’ª Much appreciated folks!
Will most likely be dedicating a short blog post to this soon to share the knowledge! đŸ™‚
j
If you have a gist or bit of code to share would love to see it, I need to do exactly this soon
c
The basic gist for having it included would be to add a step in your build targets file that includes something along the following lines:
<UmbracoJsonSchemaFiles Include="$(MSBuildThisFileDirectory)..\appsettings-schema.CUSTOM.json"/>
where the Include is the path to the file in your nuget package. Umbraco will then copy over the file and include it as a reference in its own schema: https://github.com/umbraco/Umbraco-CMS/blob/86697ff137ab6a35d5279f4c1d6991093e1bb54c/src/Umbraco.Cms.Targets/buildTransitive/Umbraco.Cms.Targets.targets#L19C1-L19C1
If you want to take it up a notch, you can take a look at uSync source code where it automatically generates its own schema file!
Took me slightly longer to get around to than I hoped, but here it is! đŸ˜‡ @Patrick de Mooij https://cornehoskam.com/posts/how-to-include-appsettings-schema-json-files-in-umbraco-packages
k
Didn't know about the schema store. Very interesting, thanks!
a
Great stuff @CornĂ© Hoskam ! Nice that you put it all together đŸ˜‰
58 Views