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

Read-Only schema properties are included in "TryIt" JSON request body #2154

Open
LukasDavSchwarz opened this issue May 26, 2022 · 1 comment
Labels
enhancement New feature or request portal triaged

Comments

@LukasDavSchwarz
Copy link

LukasDavSchwarz commented May 26, 2022

Thank you for providing awesome OpenApi Tooling!

Context

The default JSON request body of the "TryIt" panel contains properties that are marked as read-only. Requests that are sent with those example request bodies will always be invalid.

Current Behavior

The default JSON request body of the "TryIt" panel contains read-only properties.

Expected Behavior

The default JSON request body of the "TryIt" panel should omit read-only properties.

Possible Workaround/Solution

There is a workaround for POST endpoints but none for PATCH endpoints, I didn't try PUT endpoints:

The workaround for POST endpoints is to create an example request body that doesn't contain read-only properties. This doesn't work for PATCH endpoints, as Elements generates a default example that contains the example value of each property (including read-only properties) and displays that by default.

Steps to Reproduce

See "TryIt" panel of this PATCH endpoint of our OpenApi Spec: https://docs.pruefster.com/preview/v2/operations/patch-exams (Created with Stoplight Elements). The example JSON request body contains read-only properties (eg: id, token, created_at etc.) of the referenced Exam schema. Note that these properties are not displayed by Elements in the definition of the request body itself though.

  1. Create an OpenApi document (using Stoplight Studio) with a schema that contains read-only properties
  2. Create a PATCH or POST endpoint
  3. Add a JSON request body to that endpoint that references the schema from step 1
  4. The JSON request body of the "TryIt" panel of Elements for that OpenApi document should show the read-only properties of the schema

Environment

Our environment is very minimalistic and basically mirrors this HTML example that you provide in your documentation: https://meta.stoplight.io/docs/elements/ZG9jOjMyNjU4OTYz-elements-in-html

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>API Documentation | PRUEFSTER Onlineprüfungen</title>
    <meta name="description" content="API Documentation for PRUEFSTER Onlineprüfungen">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- icon -->
    <link rel="shortcut icon" href="/images/favicon.ico">

    <!-- Stoplight Elements: Web Component -->
    <script src="https://unpkg.com/@stoplight/[email protected]/web-components.min.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/@stoplight/[email protected]/styles.min.css">
    
    <!-- custom css -->
    <link rel="stylesheet" href="/css/styles_API_v2.css">
</head>

<body>

<main role="main">
    <elements-api
            apiDescriptionUrl="/openapi/v2.0.0.json"
            basePath="/preview/v2"
            logo="/images/favicon.png"
            hideInternal="true"
            hideMocking="true"
    />
</main>

<footer class="static-footer py-1">
    <div class="static-footer-container">
        <div class="footer-text">
            <a class="px-2" href="https://pruefster.com/imprint">Imprint</a>
            <a class="px-2" href="https://pruefster.com/en/privacy-policy">Privacy policy</a>
            <script>document.write(new Date().getFullYear())</script> © PRUEFSTER Onlineprüfungen GmbH
        </div>
    </div>
</footer>
</body>
</html>
  • Version used: 7.5.19 (web component)
  • Chrome Version 101.0.4951.64 (Official Build) (64-bit):
@LukasDavSchwarz
Copy link
Author

I can also try to fix this myself if you could provide me with a pointer on where to start

@mnaumanali94 mnaumanali94 added the enhancement New feature or request label Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request portal triaged
Projects
None yet
Development

No branches or pull requests

3 participants