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

#135.6 users API에 swagger 적용 #439

Merged
merged 8 commits into from
Jan 2, 2024
Merged

#135.6 users API에 swagger 적용 #439

merged 8 commits into from
Jan 2, 2024

Conversation

chlehdwon
Copy link
Contributor

@chlehdwon chlehdwon commented Dec 9, 2023

Summary

It closes #135

Extra info

users.js를 swagger을 사용하여 문서화합니다.
send message를 통일하는 과정에서 /services 코드도 일부 변경하였습니다.

Images or Screenshots

image

Further Work

  • chats 문서화
  • rooms 문서화
  • express-validator 대신 ajv만으로 validation하도록 schema 전체 변경

@chlehdwon chlehdwon self-assigned this Dec 9, 2023
@chlehdwon chlehdwon added the documentation Improvements or additions to documentation label Dec 9, 2023
Copy link
Member

@14KGun 14KGun left a comment

Choose a reason for hiding this comment

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

LGTM! 수고하셨습니다 :)

Comment on lines +11 to +34
responses: {
200: {
content: {
"text/html": {
example:
"Users/agreeOnTermsOfService : agree on Terms of Service successful",
},
},
},
400: {
content: {
"text/html": {
example: "Users/agreeOnTermsOfService : already agreed",
},
},
},
500: {
content: {
"text/html": {
example: "Users/agreeOnTermsOfService : internal server error",
},
},
},
},
Copy link
Member

Choose a reason for hiding this comment

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

이런 방법도 있네염..
왜 스웨거 코드는 볼 때마다 맘에 안든는지... 😢😢

module.exports = function (app) {

    app.get('/users/:id', (req, res) => {
        // #swagger.tags = ['User']
        // #swagger.description = 'Endpoint para obter um usuário.'
        // #swagger.parameters['id'] = { description: 'ID do usuário.' }

        /* #swagger.parameters['filtro'] = {
               in: 'query',
               description: 'Um filtro qualquer.',
               type: 'string'
        } */
        const filtro = req.query.filtro
  
        if(false)
            return res.status(404).send(false)
      
        /* #swagger.responses[200] = { 
               schema: { $ref: "#/definitions/User" },
               description: 'Usuário encontrado.' 
        } */
        return res.status(200).send(data)

    })

    app.post('/users', (req, res) => {
        /* #swagger.tags = ['User']
           #swagger.description = 'Endpoint para adicionar um usuário.' */

        /* #swagger.parameters['newUser'] = {
               in: 'body',
               description: 'Informações do usuário.',
               required: true,
               schema: { $ref: "#/definitions/AddUser" }
        } */

        const newUser = req.body

        if (true) {
            // #swagger.responses[201] = { description: 'Usuário registrado com sucesso!' }
            return res.status(201).send(data)
        }
        return res.status(500)    // #swagger.responses[500]
    })
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

코드에 주석으로 주렁주렁 달기 vs 파일 하나에 왕창 몰아넣기 이 문제네요 흑흑
개발자 지인이 말하기를 swagger는 문서화가 아니라 개발이라고 하는데 맞는 것 같습니다...
나중에 저런 반복되는 부분은 code랑 text만 받아서 생성되게 자동화 하면 훨씬 깔끔해질 것 같은데 한 번 해볼게요~!

@14KGun 14KGun merged commit 04568d5 into dev Jan 2, 2024
1 check passed
@14KGun 14KGun deleted the #135.6-docs-users branch January 2, 2024 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API 검수
2 participants