Azure / typespec-azure

About TypeSpec Azure Libraries
https://azure.github.io/typespec-azure/
MIT License
15 stars 41 forks source link

[Client emitter] Generate a metadata file while emitting #1758

Open lmazuel opened 1 week ago

lmazuel commented 1 week ago

We want to save some metadata in a file along with the emitted code, that can be used for some automation purposes. For instance, @weshaggard would want to use it to build a mapping of package version with support api-version

Proposal

Create a file metadata.json that contains:

{
  "api-version": "2015-06-01"
}

This file is not generated by default, and is enabled if the flag emit-metadata: true is passed in the tspconfig.yaml.

Each emitter will need to do that code, as TCGC should not be responsible to write files on disk. We could have though TCGC building the dict for us, with a getMetadataInfo() that emitters just have to put on disk. This way, this is consistent cross-language.

msyyc commented 1 week ago

I think the proposal makes sense. About the filename, since SDK users usually don't need care about it, we could mark it with _ to declare it is inner file so maybe _metadata.json is better.

tadelesh commented 1 week ago

though tcgc should be a lib depended by language's emitter, it has the ability to emit the metadata file if needed.

lmazuel commented 1 week ago

@srnagar is suggesting we're merging that with the current apiview_properties.json file, and I feel it makes sense to avoid having too much files

tadelesh commented 1 week ago

@srnagar is suggesting we're merging that with the current apiview_properties.json file, and I feel it makes sense to avoid having too much files

agree. emitter could use client.apiVersions[-1] to get the api version. @iscai-msft do you think we need to add more explicit property in SdkClientType to indicate the api version client generated from?

iscai-msft commented 1 week ago

we have getDefaultApiVersion right now, I feel that's the best way to do it. We could add a defaultApiVersion property, but I think we're good for now

tadelesh commented 1 week ago

getDefaultApiVersion need the raw typespec namespace. i don't think it is a good way to get default.

iscai-msft commented 1 week ago

Hmm that's a very good point, yes we can go with client.apiVersions[-1] for now / add another property, but I think we can go without adding the property for now