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

feat: add reference openapi mock apiproxy implementation #761

Merged
merged 5 commits into from
Oct 31, 2024

Conversation

micovery
Copy link
Contributor

Description

Add a reference implementation that shows how to create a feature rich mock API proxy using an OpenAPI 3 specification.

The reference implementation supports the following features:

  • CORS (using Apigee CORS policy)
  • Request Validation (using Apigee OASValidation)
  • Dynamic Response Status Code (using a custom JavaScript policy)
  • Dynamic Response Content Type (using a custom JavaScript policy)
  • Dynamic Response Body (using a custom JavaScript policy)

Housekeeping

(please check all that apply [x], do not edit the text)

  • I have run all the tests locally and they all pass.
  • I have followed the relevant style guide for my changes.

Full Repo Validation Required

(please check all that apply [x], do not edit the text)

  • PR requires full pipeline run (Run for changes only by default).

CC: @apigee-devrel-reviewers

@micovery
Copy link
Contributor Author

/gcbrun

@danistrebel
Copy link
Collaborator

/gcbrun

@apigee-devrel-bot
Copy link

Pipeline Report

Pipeline Result Elapsed Wall Time
references/openapi-mock pass 6s
TOTAL PIPELINE pass 6s

View details in Cloud Build (permission required)

Commit version: 99daf81

@micovery micovery force-pushed the main branch 2 times, most recently from 5131b95 to c5a8065 Compare October 31, 2024 16:16
@OmidTahouri
Copy link
Collaborator

/gcbrun

@apigee-devrel-bot
Copy link

Pipeline Report

Pipeline Result Elapsed Wall Time
references/openapi-mock pass 6s
TOTAL PIPELINE pass 6s

View details in Cloud Build (permission required)

Commit version: 1bc7966


Under the hood, it is using the same reference implementation JavaScript policy from this repo.

Finally, you just as shown before, you would use the [Apigee CLI](https://github.com/apigee/apigeecli/releases/) to deploy the API proxy bundle.
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo? "you just"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

The reference mock API proxy supports the following features.

* [CORS](#cors) (using Apigee [CORS](https://cloud.google.com/apigee/docs/api-platform/reference/policies/cors-policy) policy)
* [Request Validation](#request-validation) (using Apigee [OASValidation](https://cloud.google.com/apigee/docs/api-platform/reference/policies/oas-validation-policy))
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo: double space

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went through the whole MD file and remove all instances of double spaces like this one.


## Customizing The Mock API Proxy

This [reference implementation](./apiproxy) provides a solid foundation for building your own mock API proxy. You can customize it by adding your own policies, modifying the existing configuration, and using your own OpenAPI specification. This is a great way to learn about Apigee or to achieve more advanced customizations.
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo: double space

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went through the whole MD file and remove all instances of double spaces like this one.


At the very minimum, you have to:

1. Update the `<BasePath>/v3/petstore</BasePath>` element within the [default.xml](./apiproxy/proxies/default.xml) proxy endpoint.
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo: double space

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went through the whole MD file and remove all instances of double spaces like this one.

references/openapi-mock/README.md Show resolved Hide resolved
**Want more control?** You can use headers to select the response Content-Type:

* **Standard `Accept` header:** You can use the standard `Accept` header in your request to request a specific media type (e.g., `Accept: application/xml`).
* **Random media type:** Alternatively, use the `Mock-Fuzz: true` header to have the proxy select a random media type the available ones.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the same Mock-Fuzz header used for random status codes, content-types and response body? How does that work?

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, Mock-Fuzz in general is used a hint to tell the Proxy that you want the dynamic behavior. However, it always has less precedence than the Mock-Status and the Accept header.

references/openapi-mock/pipeline.sh Outdated Show resolved Hide resolved
Copy link
Collaborator

@OmidTahouri OmidTahouri left a comment

Choose a reason for hiding this comment

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

LGTM

@OmidTahouri
Copy link
Collaborator

/gcbrun

@apigee-devrel-bot
Copy link

Pipeline Report

Pipeline Result Elapsed Wall Time
references/openapi-mock fail 71s
TOTAL PIPELINE pass 71s

View details in Cloud Build (permission required)

Commit version: 95c3737

@OmidTahouri
Copy link
Collaborator

/gcbrun

@apigee-devrel-bot
Copy link

Pipeline Report

Pipeline Result Elapsed Wall Time
references/openapi-mock fail 80s
TOTAL PIPELINE pass 80s

View details in Cloud Build (permission required)

Commit version: 69521db

@OmidTahouri
Copy link
Collaborator

/gcbrun

@apigee-devrel-bot
Copy link

Pipeline Report

Pipeline Result Elapsed Wall Time
references/openapi-mock pass 62s
TOTAL PIPELINE pass 62s

View details in Cloud Build (permission required)

Commit version: 1eb0d1a

@OmidTahouri OmidTahouri merged commit 874853e into apigee:main Oct 31, 2024
7 checks passed
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.

4 participants