Skip to content

Modify, clean, refactor for the OpenApiDocument and OpenApiPaths#46

Merged
xuzhg merged 3 commits into
microsoft:masterfrom
xuzhg:DocumentAndPathsChanges
Oct 31, 2017
Merged

Modify, clean, refactor for the OpenApiDocument and OpenApiPaths#46
xuzhg merged 3 commits into
microsoft:masterfrom
xuzhg:DocumentAndPathsChanges

Conversation

@xuzhg

@xuzhg xuzhg commented Oct 31, 2017

Copy link
Copy Markdown
Contributor
  1. Modify, cleanup, refactor, correct for OpenApiDocument

  2. Create a new class named OpenApiDictionaryElement

  3. Modify, cleanup, refactor, correct for OpenApiPaths

@PerthCharern

Copy link
Copy Markdown
Contributor

Let's document public properties.


Refers to: src/Microsoft.OpenApi/Models/OpenApiDictionaryElement.cs:91 in e6a33b8. [](commit_id = e6a33b8, deletion_comment = False)

writer.WriteObject("info", Info, (w, i) => i.WriteAsV3(w));
writer.WriteList("servers", Servers, (w, s) => s.WriteAsV3(w));
writer.WritePropertyName("paths");
// openapi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

// openapi [](start = 12, length = 10)

These comments look cluttered to me. I don't think they are necessary. What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I suggest to leave these comments there for better understanding which parts are being written.
Is it ok for you?

writer.WriteList("servers", Servers, (w, s) => s.WriteAsV3(w));
writer.WritePropertyName("paths");
// openapi
writer.WriteStringProperty(OpenApiConstants.OpenApiDocOpenApi, "3.0.0");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"3.0.0" [](start = 75, length = 7)

Leverage your constant

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or use the Version property in this class

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changed.

/// <summary>
/// REQUIRED.This string MUST be the semantic version number of the OpenAPI Specification version that the OpenAPI document uses.
/// </summary>
public Version Version { get; set; } = OpenApiConstants.OpenApiDocDefaultVersion;

@PerthCharern PerthCharern Oct 31, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this need to exist here? It's not in the spec. #Closed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh. I see what's being done here. This corresponds to the "openapi" property in the spec. Can we name this SpecificationVersion to avoid confusion with the other version in the Info?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok.

writer.WriteStringProperty(OpenApiConstants.OpenApiDocSwagger, "2.0");

// info
writer.WriteObject("info", Info, (w, i) => i.WriteAsV2(w));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"info" [](start = 31, length = 6)

leverage your constant

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@PerthCharern

Copy link
Copy Markdown
Contributor
        writer.WriteEndArray();

This logic should be in OpenApiServer.WriteAsV2

(The same principle should apply to the SecurityScheme/SecurityRequirement stuff as well)


Refers to: src/Microsoft.OpenApi/Models/OpenApiDocument.cs:189 in e6a33b8. [](commit_id = e6a33b8, deletion_comment = False)

{
internal static class OpenApiDocumentTestHelper
{
public static void CreatePath(this OpenApiDocument doc, string key, Action<OpenApiPathItem> configure)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

public [](start = 8, length = 6)

Document. Also, where is this used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It seems only used in the ExampleTests.cs and ValidationTests.cs. So, I move it from OpenApiDocument to test project.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changed "doc" to "document"

writer.WriteExtensions(Extensions);

writer.WriteEndObject();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd rather have WriteAsV2 and WriteAsV3 implement this logic separately. It might be duplicate code, but technically they are somewhat independent, and it will be easier to fix them individually if needs be in the future.

What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Either is ok for me. But I changed follow up your suggestion.

@PerthCharern

Copy link
Copy Markdown
Contributor

Let's add more extensive unit tests for paths.

@xuzhg

xuzhg commented Oct 31, 2017

Copy link
Copy Markdown
Contributor Author

1. Let's add more extensive unit tests for paths.

I want to leave it when I back to change "OpenApiPathItem".

This logic should be in OpenApiServer.WriteAsV2 (The same principle should apply to the SecurityScheme/SecurityRequirement stuff as well)
I am not familiar with V3 -> V2. But, it supposed to leave it when I back to change "OpenApiSe...".

Let's document public properties.

done.

writer.WriteObject("info", Info, (w, i) => i.WriteAsV2(w));
SerializeHostInfo(writer, Servers);
// swagger
writer.WriteStringProperty(OpenApiConstants.OpenApiDocSwagger, OpenApiConstants.OpenApiDocSwaggerVersion);

@PerthCharern PerthCharern Oct 31, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OpenApiConstants.OpenApiDocSwaggerVersion [](start = 75, length = 41)

If above uses SpecVersion, we should use SpecVersion here too.

@PerthCharern

Copy link
Copy Markdown
Contributor

@xuzhg I can take up the V2 object writing issues. I'll sign off.

@PerthCharern PerthCharern left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:shipit:

@xuzhg

xuzhg commented Oct 31, 2017

Copy link
Copy Markdown
Contributor Author

Great, Thanks.

@xuzhg xuzhg merged commit 9df3f3d into microsoft:master Oct 31, 2017
@xuzhg xuzhg deleted the DocumentAndPathsChanges branch October 31, 2017 22:36
baywet added a commit that referenced this pull request Nov 11, 2025
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.

2 participants