Skip to content

add the write functionality for each open api element#42

Merged
xuzhg merged 13 commits intomicrosoft:masterfrom
xuzhg:AddWriteForElement
Oct 31, 2017
Merged

add the write functionality for each open api element#42
xuzhg merged 13 commits intomicrosoft:masterfrom
xuzhg:AddWriteForElement

Conversation

@xuzhg
Copy link
Contributor

@xuzhg xuzhg commented Oct 27, 2017

1 .Separate the functions into the Open Api element. See related PR #41

  1. Change the OpenApiSerializer to OpenApiElementSerializeExtension.

@xuzhg
Copy link
Contributor Author

xuzhg commented Oct 27, 2017

@PerthCharern
Please take a look at #42. And Compare between #41 and #42.

@xuzhg
Copy link
Contributor Author

xuzhg commented Oct 27, 2017

@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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

virtual [](start = 15, length = 7)

No need for virtual ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

@xuzhg xuzhg Oct 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far no. But who knows. 😄

@PerthCharern
Copy link
Contributor

I prefer #42 over #41. IMO, Extension methods are unnecessary in this scenario and lead to overabundance of classes.

writer.WriteList("servers", Servers, (w, s) => s.WriteAsV3(w));
writer.WritePropertyName("paths");

writer.WriteStartObject();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writer.WriteStartObject(); [](start = 11, length = 27)

This Start/End object should be moved to the Paths object to be consistent with the other models.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. That's what I will work to change/refactor each "OpenApiXXX".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the value of making this change. I only see disadvantages.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darrelmiller Could you elaborate? That is how it's being done for other objects.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@xuzhg
Copy link
Contributor Author

xuzhg commented Oct 27, 2017

@PerthCharern

Please see my commit 3, I will do like this for all OpenApiXXX one by one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@xuzhg
Copy link
Contributor Author

xuzhg commented Oct 30, 2017

@darrelmiller @PerthCharern

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.

@darrelmiller
Copy link
Member

@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?

@xuzhg
Copy link
Contributor Author

xuzhg commented Oct 30, 2017

@darrelmiller

If I make them internal, I can't use the "interface", Then I can't use it as generic method in the following file:
https://github.com/Microsoft/OpenAPI.NET/pull/42/files#diff-214dd7887368cc85c3762d5b0ef3c289

@darrelmiller
Copy link
Member

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())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PerthCharern I think we should add this back because "an extra line break is not reasonable for the single property."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PerthCharern

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darrelmiller what do you think about the "empty" yaml. It's empty or a whitespace?

Copy link
Member

@darrelmiller darrelmiller Oct 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@xuzhg
Copy link
Contributor Author

xuzhg commented Oct 30, 2017

@darrelmiller @PerthCharern

I make the method as internal in the latest commit. Would you please take a look?


expectedYaml = expectedYaml.MakeLineBreaksEnvironmentNeutral();

// Assert
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should put back expectedYaml = expectedYaml.MakeLineBreaksEnvironmentNeutral();

This makes sure this test passes in any OS environment it's run.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

@PerthCharern PerthCharern Oct 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is not really related to that though. This applies to all line breaks. #Closed

Copy link
Contributor Author

@xuzhg xuzhg Oct 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I re-added it back. #Closed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Not supported Open Api document format!" [](start = 47, length = 41)

$"The given OpenAPI format is not supported: {format}."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I changed it and move it to SRResource.resx.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Unknown Open API specification version." [](start = 47, length = 41)

$"The given OpenAPI specification version is not supported: {specVersion}."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I changed it and move it to SRResource.resx.

@xuzhg
Copy link
Contributor Author

xuzhg commented Oct 30, 2017

@darrelmiller @PerthCharern

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v2.0

Copy link
Contributor Author

@xuzhg xuzhg Oct 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed. #Closed

}
else
{
writer.WriteValue("[]");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say some hardcoded value like this should be the responsibility of the writer. The DOM should call something like writer.WriteEmptyArray()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I am working on cleanup/refactor the DOM one by one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be an issue since for V2, these properties are a part of the SecurityScheme object, not a new object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Please see the WriteAsV2(writer) in the OpenApiSecurityScheme.cs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes. let me think it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with checking this overall architecture in first. We can tackle these isolated issues separately if you like.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't do this in this extension. If you need this functionality, then please separate it to a new extension.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I changed it.

Copy link
Contributor

@PerthCharern PerthCharern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@xuzhg xuzhg merged commit d062eb7 into microsoft:master Oct 31, 2017
@xuzhg xuzhg deleted the AddWriteForElement branch October 31, 2017 00:01
baywet added a commit that referenced this pull request Nov 11, 2025
sync from upstream main to feat 3 2
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

Successfully merging this pull request may close these issues.

3 participants

Comments