OpenApi 3.0 requestBody required
Asked Answered
G

1

7

I use postman and i create API with the openAPI 3.0. Problem is when i send this request, if i add body or not it return status code 200. I don't understand because i said i my code required for requestbody and for field in this body but nothing worth (without body code 200 and without GRP_CNOM code 200)... SomeOne can help me ?

my openAPI code :

        post:
            operationId: CreationGroup
            summary: Creation groupe
            requestBody:
                $ref: '#/components/requestBodies/crea'
            responses:
                '200':
                    description: '200 - Création du groupe effectué'
                    content:
                        application/json:
                            schema:
                                type: object
                                properties:
                                    code:
                                        type: integer
                                    message:
                                        type: string
                                example:
                                    code: 200
                                    message: Le groupe a bien été créé
                '400':
                    description: '400 - Création du groupe échouée'
                    content:
                        application/json:
                            schema:
                                type: object
                                properties:
                                    code:
                                        type: integer
                                    message:
                                        type: string
                                example:
                                    code: 200
                                    message: Le groupe a échouée
                '401':
                    $ref: '#/components/responses/UnauthorizedError'
                default:
                    description: 'Erreur'
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/Error'
components:
    requestBodies:
        crea:
            required: true
            content:
                application/json:
                    schema:
                        $ref: '#/components/schemas/Group'
                    example:
                        $ref: '#/components/examples/oneGroupOrga'
    securitySchemes:
        jwtAuth:       
            type: http
            scheme: bearer
            bearerFormat: JWT
    examples:
        oneGroupOrga:
            value:
                GRP_CNOM: Princ
                GRP_SPKGROUPE: 2
                GRP_SFKINSTANCE: 1
                GRP_CBORDERCOLOR: "#F5370E"
                GRP_BSOCIETE: true
                GRP_BETABLISSEMENT: true
                GRP_BUNITE: false
                GRP_CSIRET: null
                GRP_SFKAPE: 1
                GRP_CCAPITAL: "200000"
                GRP_SMOISDEBUTEXERCICECOMPTABLE: 1
                GRP_CABREVIATIONSOCIETE: PR
                GRP_CNUMEROTVAINTRACOMMUNAUTAIRE: ""
                GRP_DCOEFFICIENTENCOURSCOMPTABLE: 70
                GRP_CADRESSE: 113 boulevard de Lamasquère
                GRP_CCODEPOSTAL: "31600"
                GRP_SFKVILLE: 1
                GRP_SFKPAYS: 1
                GRP_CEN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Nkji3Lk6JCQm8mst0VwIQYuypbmFxVROLoLWgo2dBImGS5ehZ6OmNWERQtOrme3atcyDkSgS0sv2mD8am+B0OKWdSijCIoSmE3mqvr7+8UYnsWDx+PETmn2qe5iwCCFIzMOeaWzzCgdhE/L/AvwHYmZzkF16ZVcAAAAASUVORK5CYII="
                GRP_CPIEDDEPAGETEXTE: "113 boulevard de Lamasquère - 31600 MURET - 890720824"
                GRP_SFKFONCTION: 1
                GRP_DNOTATION: null
                GRP_CCOMMENTAIRE: null
                GRP_SFKFORMBUILDER: 1
                GRP_CSIREN: "890 720 824"
                GEG_SFKGROUPEPARENT120: 1
                GRP_SFKGROUPETYPE: 650
                ADM_COMPTEBANCAIRE:
                    -
                        CBC_SPKCOMPTE: 1
                        CBC_CNOMDUCOMPTE: Compte courant
                        CBC_CNOMDELABANQUE: CIC
                        CBC_CDOMICILIATION: ""
                        CBC_CBIC: ""
                        CBC_CRIB: ""
                        CBC_CIBAN: ""
                        CBC_BPARDEFAUT: true
                ADM_UTILISATEUR_GROUPE:
                    -
                        UGR_SFKUTILISATEUR: 1
                        UGR_SFKFONCTION: 2
    schemas:
        Group:
            type: object
            discriminator:
                propertyName: GRP_CNOM
            required:
                -
                    GRP_CNOM
            properties:
                GRP_CNOM:
                    type: string
                GRP_SPKGROUPE:
                    type: integer
                GRP_SFKINSTANCE:
                    type: integer
                GRP_SFKROLE:
                    type: integer
                    nullable: true
                GRP_CBORDERCOLOR:
                    type: string
                    nullable: true
                GRP_BSOCIETE:
                    type: boolean
                GRP_BETABLISSEMENT:
                    type: boolean
                GRP_BUNITE:
                    type: boolean
                GRP_CSIRET:
                    type: string
                    nullable: true
                GRP_SFKAPE:
                    type: integer
                    nullable: true
                GRP_CCAPITAL:
                    type: string
                    nullable: true
                GRP_SMOISDEBUTEXERCICECOMPTABLE:
                    type: integer
                    nullable: true
                GRP_CABREVIATIONSOCIETE:
                    type: string
                    nullable: true
                GRP_CNUMEROTVAINTRACOMMUNAUTAIRE:
                    type: string
                    nullable: true
                GRP_DCOEFFICIENTENCOURSCOMPTABLE:
                    type: number
                    nullable: true
                GRP_CADRESSE:
                    type: string
                    nullable: true
                GRP_CCODEPOSTAL:
                    type: string
                    nullable: true
                GRP_SFKVILLE:
                    type: integer
                    nullable: true
                GRP_SFKPAYS:
                    type: integer
                    nullable: true
                GRP_CENTETETEXTE:
                    type: string
                    nullable: true
                GRP_CENTETEIMAGE:
                    type: string
                    format: byte
                    nullable: true
                GRP_CPIEDDEPAGEIMAGE:
                    type: string
                    format: byte
                    nullable: true
                GRP_CPIEDDEPAGETEXTE:
                    type: string
                    nullable: true
                GRP_SFKFONCTION:
                    type: integer
                    nullable: true
                GRP_DNOTATION:
                    type: number
                    nullable: true
                GRP_CCOMMENTAIRE:
                    type: string
                    nullable: true
                GRP_SFKFORMBUILDER:
                    type: integer
                    nullable: true
                GRP_CSIREN:
                    type: string
                    nullable: true
                GEG_SFKGROUPEPARENT120:
                    type: integer
                    nullable: true
                GRP_SFKGROUPETYPE:
                    type: integer
                    enum:
                        -
                            650
                        -
                            651
                        -
                            652
                GEG_SFKGROUPEENFANT122:
                    type: array
                    items:
                        type: string
                GEG_SFKGROUPEENFANT121:
                    type: array
                    items:
                        type: object
                        properties:
                            GRP_SPKGROUPE:
                                type: integer
                            GRP_SFKGROUPETYPE:
                                type: integer
                                enum:
                                    -
                                        650
                                    -
                                        651
                                    -
                                        652
                        required:
                            -
                                GRP_SPKGROUPE
                            -
                                GRP_SFKGROUPETYPE
                ADM_COMPTEBANCAIRE:
                    type: array
                    items:
                        type: object
                        properties:
                            CBC_SPKCOMPTE:
                                type: integer
                            CBC_CNOMDUCOMPTE:
                                type: string
                            CBC_CNOMDELABANQUE:
                                type: string
                            CBC_CDOMICILIATION:
                                type: string
                            CBC_CBIC:
                                type: string
                            CBC_CRIB:
                                type: string
                            CBC_CIBAN:
                                type: string
                            CBC_BPARDEFAUT:
                                type: boolean
                                default: false
                        required:
                            -
                                CBC_CNOMDUCOMPTE
                ADM_UTILISATEUR_GROUPE:
                    type: array
                    items:
                        type: object
                        properties:
                            UGR_SFKUTILISATEUR:
                                type: integer
                            UGR_SFKFONCTION:
                                type: integer
                            UGR_SFKDROIT:
                                type: integer
                                enum:
                                    -
                                        59
                                    -
                                        60
                        required:
                            -
                                UGR_SFKUTILISATEUR
        Error:
            type: object
            properties:
                code:
                    type: integer
                    format: int32
                message:
                    type: string
    responses:
        UnauthorizedError:
            description: Le token est invalid ou manquant
security:
    - 
        jwtAuth: [] ```
Grunberg answered 18/11, 2020 at 12:36 Comment(2)
It looks like the API server accepts this request both with and without the body. This is typically controlled in the API code, not necessarily in the OpenAPI definition.Colchicine
Thanks for your reply. Yes so how can i do that ?Grunberg
C
6

You can place the required in the paths instead of the components. For example:

[...]
post:
    operationId: CreationGroup
    summary: Creation groupe
    requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/requestBodies/crea'
        responses:
[...]

If required would be in components then it would be required every time its used. However, in reality, whether a request body is required depends on the route. That is why they like you to put it in the paths section.

Culbreth answered 27/10, 2021 at 11:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.