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

fix: generation of openapi spec when there are no changes #1304

Merged
merged 2 commits into from
Mar 24, 2022

Conversation

dnephin
Copy link
Contributor

@dnephin dnephin commented Mar 23, 2022

Summary

I noticed the date update problem was happening again after #1290.

Using reflect.Equal does not appear to work, there must be differences between how the spec is decoded from a file, and generated from types.

This PR replaces the the date with the product version. Thanks to @mxyng , we can set this version from the please-release github action.

Checklist

  • Wrote appropriate unit tests
  • Considered security implications of the change
  • Updated associated docs where necessary
  • Updated associated configuration where necessary
  • Change is backwards compatible if it needs to be (user can upgrade without manual steps?)
  • Nothing sensitive logged
  • Commit message conforms to Conventional Commit
  • GitHub Actions are passing

Builds on #1290

@dnephin dnephin requested a review from ssoroka March 23, 2022 21:00
@dnephin dnephin force-pushed the dnephin/openapi-spec-date branch 3 times, most recently from 2715f62 to 374f010 Compare March 23, 2022 23:14
return fmt.Errorf("failed to write schema: %w", err)
}
return nil
}

func WriteOpenAPISpecToFile(filename string) error {
old, err := readOpenAPISpec(filename)
fh, err := os.Create(filename)
Copy link
Collaborator

Choose a reason for hiding this comment

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

does this need to be explicitly closed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, it definitely does need to be closed. Good catch!

@dnephin dnephin force-pushed the dnephin/openapi-spec-date branch 2 times, most recently from 9ad0a30 to b7d66ce Compare March 24, 2022 17:58
dnephin and others added 2 commits March 24, 2022 16:42
Using reflect.Equal does not appear to work, there must be differences
between how the spec is decoded from a file, and generated from types.

This commit goes back to comparing the encoded version of the spec. That
works better, but requires that we don't append servers, otherwise the
old spec will always have different servers.

All of the other fields we set are from writeOpenAPISpec replace any
existing values, so it seems appropriate to do the same for Servers.
This allows us to remove the comparison logic and simply re-generate the spec file every time.

Co-Authored-By: Michael Yang <michael.yang@infrahq.com>
@dnephin dnephin merged commit 67d0240 into main Mar 24, 2022
@dnephin dnephin deleted the dnephin/openapi-spec-date branch March 24, 2022 20:53
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