add the write functionality for each open api element#42
add the write functionality for each open api element#42xuzhg merged 13 commits intomicrosoft:masterfrom xuzhg:AddWriteForElement
Conversation
|
@PerthCharern |
|
Please take a look this PR. I will work on the code improvement/cleanup for each OpenApiXXXX, and will add Unit test for each OpenApiXXXX. |
There was a problem hiding this comment.
virtual [](start = 15, length = 7)
No need for virtual ?
There was a problem hiding this comment.
Maybe I am wrong.
I want to give customer a functionality to create their own OpenApiXXX and derived from "OpenApiCallback", they can override these methods.
There was a problem hiding this comment.
Interesting - I didn't think of that scenario. I'm not sure how they would use that new class they created since the objects are defined here with classes we have. It would be a cool thing nonetheless to allow this to be customizable.
Do you happen to have some specific use case in mind?
There was a problem hiding this comment.
So far no. But who knows. 😄
| writer.WriteList("servers", Servers, (w, s) => s.WriteAsV3(w)); | ||
| writer.WritePropertyName("paths"); | ||
|
|
||
| writer.WriteStartObject(); |
There was a problem hiding this comment.
writer.WriteStartObject(); [](start = 11, length = 27)
This Start/End object should be moved to the Paths object to be consistent with the other models.
There was a problem hiding this comment.
Yes. That's what I will work to change/refactor each "OpenApiXXX".
There was a problem hiding this comment.
I don't understand the value of making this change. I only see disadvantages.
There was a problem hiding this comment.
@darrelmiller Could you elaborate? That is how it's being done for other objects.
There was a problem hiding this comment.
@xuzhg @darrelmiller I still think this one-off inconsistency should be fixed. But if you'd rather do this later, I can overlook this for now.
There was a problem hiding this comment.
Actually, we probably have to do this the other way round since some two objects in the DOM can be one object in the document when we do V3 -> V2.
|
Please see my commit 3, I will do like this for all OpenApiXXX one by one. |
There was a problem hiding this comment.
Why are we putting writer function back into the model classes? It was intentional not to do this. The idea was to have all structural rules relating to a particular version in a single class, not scattered across the model classes.
|
So, we discussed to take this PR to move forward, would you please take a look and sign off? For change to the "public virtual void WriteAsV2(3)" as "internal virtual void WriteAsV2(3)", I have to say that I need this to be public then I can use it in the generic serialize function for customer to use. |
|
@xuzhg I'm sure I follow why the WriteAs methods need to be public. The Writers/Serializers that need them are in the same project, no? |
|
If I make them internal, I can't use the "interface", Then I can't use it as generic method in the following file: |
|
Can we then at least make the interface implementation explicit so that we don't clutter up the public interface of the DOM classes? |
| else | ||
| { | ||
| Writer.WriteLine(); | ||
| if (!IsTopLevelObjectScope()) |
There was a problem hiding this comment.
@PerthCharern I think we should add this back because "an extra line break is not reasonable for the single property."
There was a problem hiding this comment.
Not sure if I fully agree with that. I don't see the point of having this as a special case. Adding a line break in the beginning is not wrong, and makes more sense if we plan to start the doc with ---.
If we will not start the doc with ---, then I think it makes sense that you are adding it back.
There was a problem hiding this comment.
Can I file an issue to improve the yaml writer later? To be honest, I am not familiar with the Yaml spec a lot. So, the Yaml writer maybe has some violation with the Spec.
There was a problem hiding this comment.
@darrelmiller what do you think about the "empty" yaml. It's empty or a whitespace?
There was a problem hiding this comment.
I would expect it to be empty. Non-significant whitespace does not tend to get output by YAML serializers. http://yaml.org/spec/1.2/spec.html#id2775170
|
I make the method as internal in the latest commit. Would you please take a look? |
|
|
||
| expectedYaml = expectedYaml.MakeLineBreaksEnvironmentNeutral(); | ||
|
|
||
| // Assert |
There was a problem hiding this comment.
I think we should put back expectedYaml = expectedYaml.MakeLineBreaksEnvironmentNeutral();
This makes sure this test passes in any OS environment it's run.
There was a problem hiding this comment.
Yes. I totally agree. But it is related to the discussion of "New line break at the starting of the Yaml document". I suggest to leave it to fix at #39. Is it ok?
There was a problem hiding this comment.
This one is not really related to that though. This applies to all line breaks. #Closed
There was a problem hiding this comment.
Ok. I re-added it back. #Closed
There was a problem hiding this comment.
"Not supported Open Api document format!" [](start = 47, length = 41)
$"The given OpenAPI format is not supported: {format}."
There was a problem hiding this comment.
Thanks, I changed it and move it to SRResource.resx.
There was a problem hiding this comment.
"Unknown Open API specification version." [](start = 47, length = 41)
$"The given OpenAPI specification version is not supported: {specVersion}."
There was a problem hiding this comment.
Thanks, I changed it and move it to SRResource.resx.
|
Sorry, I think That's all commits for this PRs. I continue on the clean/refactor for other DOM and try to add Unit test for each of them. I will send another PRs for them. |
| } | ||
| else | ||
| { | ||
| writer.WriteValue("[]"); |
There was a problem hiding this comment.
I'd say some hardcoded value like this should be the responsibility of the writer. The DOM should call something like writer.WriteEmptyArray()
There was a problem hiding this comment.
Agreed. I am working on cleanup/refactor the DOM one by one.
There was a problem hiding this comment.
This is going to be an issue since for V2, these properties are a part of the SecurityScheme object, not a new object.
There was a problem hiding this comment.
Yes. Please see the WriteAsV2(writer) in the OpenApiSecurityScheme.cs
There was a problem hiding this comment.
Right. I saw that. That's why this will be an issue. We should not be writing the start of a new object. These properties here are a part of the Scheme object.
It might make more sense to put all these WriteStartObject and WriteEndObject in the caller, so that you can choose to call or not call whenever you want. If we go that route, we should consistently go that route for all calls.
There was a problem hiding this comment.
Oh, yes. let me think it.
There was a problem hiding this comment.
I'm fine with checking this overall architecture in first. We can tackle these isolated issues separately if you like.
There was a problem hiding this comment.
Originally, I want to take this DOM cleanup/refactor later. But for this you mentioned, I changed it in my latest commit. Would you please take a look?
There was a problem hiding this comment.
Please don't do this in this extension. If you need this functionality, then please separate it to a new extension.
PerthCharern
left a comment
There was a problem hiding this comment.
It's great that we can unit test each element now. Thanks for making this change Sam.
There are still a couple of open issues, but they are isolated, so I'll sign off, so that we can get this overall structure checked in and start working on those bugs.
- Where should WriteStartObject / WriteEndObject go?
- Some DOMs might not be 100% correct yet (e.g. SecurityScheme). We need to fix them.
- Newline issues in YAML/Extensions
sync from upstream main to feat 3 2
1 .Separate the functions into the Open Api element. See related PR #41