Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lookup schema with discriminator in OpenAPI snippets #1604

Merged
merged 9 commits into from
Jun 19, 2023

Conversation

andrueastman
Copy link
Member

@andrueastman andrueastman commented Jun 19, 2023

This PR closes #629

It updates the OpenAPI snippet generator to receive the list of schemas in the reference document so as to allow for the lookup of schemas on snippet generation. This assists in the scenario where the node schema defines the base type (e.g. Attachment) but the payload defines a derived type(e.g. FileAttachement) with the properties from the derived type.
As the generator only has the types from the base type, it ends up placing the properties of the derived instance in the additionalDAta rather than initialize the derived type and use its propeties.

For example

var requestBody = new Attachment
{
	OdataType = "#microsoft.graph.fileAttachment",
	Name = "smile",
	AdditionalData = new Dictionary<string, object>
	{
		{
			"contentBytes" , "R0lGODdhEAYEAA7"
		},
	},
};

Should be

var requestBody = new FileAttachment
{
	OdataType = "#microsoft.graph.fileAttachment",
	Name = "smile",
	ContentBytes = Convert.FromBase64String("R0lGODdhEAYEAA7"),
};

As the changes affect the SnippetCodeGraph, the fix should apply for all languages using the SnippetCodeGraph and type information updated.

This PR also

For easier review the PR is composed of 2 updates

Generation Diff

@andrueastman andrueastman self-assigned this Jun 19, 2023
@andrueastman andrueastman marked this pull request as ready for review June 19, 2023 13:22
@andrueastman andrueastman requested a review from a team as a code owner June 19, 2023 13:22
@andrueastman andrueastman enabled auto-merge (squash) June 19, 2023 13:22
baywet
baywet previously requested changes Jun 19, 2023
CodeSnippetsReflection.OpenAPI/SnippetModel.cs Outdated Show resolved Hide resolved
@sonarcloud
Copy link

sonarcloud bot commented Jun 19, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

88.3% 88.3% Coverage
0.0% 0.0% Duplication

@andrueastman andrueastman merged commit 846a08e into dev Jun 19, 2023
9 checks passed
@andrueastman andrueastman deleted the andrueastman/fixDerivedTypes branch June 19, 2023 14:18
andrueastman added a commit that referenced this pull request Jun 20, 2023
* Fix: Use pascal case for issue property key (#1603)

* Use pascal case for issue propety key

* Update GraphWebApi/Controllers/KnownIssuesController.cs

Co-authored-by: Eastman <andrueastman@users.noreply.github.com>

---------

Co-authored-by: Eastman <andrueastman@users.noreply.github.com>

* Lookup schema with discriminator in OpenAPI snippets (#1604)

* Use shared base to reduce code repetition

* Looks up dereived types from schema list

* Fixes template matching for collections with functions

* Fixes Guid parsing

* Fixes enum parsing in path parameters

* Fix incorrect schema names when looked up from collections

* Fix namespaces lookup for collections

* Fix code smells

* Bump Microsoft.OpenApi from 1.6.4 to 1.6.5 (#1606)

Bumps [Microsoft.OpenApi](https://github.com/Microsoft/OpenAPI.NET) from 1.6.4 to 1.6.5.
- [Release notes](https://github.com/Microsoft/OpenAPI.NET/releases)
- [Commits](microsoft/OpenAPI.NET@1.6.4...1.6.5)

---
updated-dependencies:
- dependency-name: Microsoft.OpenApi
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump Microsoft.OpenApi.Readers from 1.6.4 to 1.6.5 (#1605)

Bumps [Microsoft.OpenApi.Readers](https://github.com/Microsoft/OpenAPI.NET) from 1.6.4 to 1.6.5.
- [Release notes](https://github.com/Microsoft/OpenAPI.NET/releases)
- [Commits](microsoft/OpenAPI.NET@1.6.4...1.6.5)

---
updated-dependencies:
- dependency-name: Microsoft.OpenApi.Readers
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: EvansA <evansonoka05.j@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

Description of ContentBytes incorrect
2 participants