0Pricing
Spring Boot 4 Microservices & REST APIs · บทเรียน

Swagger UI

สำรวจและทดสอบ API แบบโต้ตอบ

Swagger UI เป็นบทเรียน Spring Boot 4 Microservices & REST APIs ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Spring Boot 4 Microservices & REST APIs และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Spring Boot 4 Microservices & REST APIs มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

What is Swagger UI?

Swagger UI renders your OpenAPI spec as an interactive web page. Developers can browse endpoints, read schemas, and send live requests - all from the browser.

Where it lives

With the -ui starter, Swagger UI is served at /swagger-ui.html by default. It loads the spec from /v3/api-docs.

// open in a browser:
// http://localhost:8080/swagger-ui.html

Try it out

Each operation has a Try it out button. You fill in parameters and body, click Execute, and the UI shows the real request URL, response status, headers and body.

Reading the schema view

The Schemas section at the bottom lists every model with field types, descriptions and examples taken from your @Schema annotations.

Changing the UI path

Relocate the UI with a property - useful when serving docs under a custom route.

# application.yml
springdoc:
  swagger-ui:
    path: /docs

Sorting endpoints and tags

By default operations appear in an unsorted order. Properties let you sort operations and tags alphabetically for a cleaner page.

springdoc:
  swagger-ui:
    operations-sorter: alpha
    tags-sorter: alpha

Trying secured endpoints

If you declared a security scheme, the UI shows an Authorize button. Enter a token once and it is attached to every secured request you try.

Filtering operations

Enable a search box to filter the long list of endpoints by name, which helps in large APIs.

springdoc:
  swagger-ui:
    filter: true

Display options

You can control how much is expanded by default and whether request duration is shown, tuning the UI for your team's taste.

springdoc:
  swagger-ui:
    doc-expansion: none      # collapse all by default
    display-request-duration: true

Securing the UI itself

Swagger UI exposes your API surface. In production, protect /swagger-ui/** and /v3/api-docs/** with Spring Security, or disable them, so they are not publicly browsable.

// permit only authenticated users
http.authorizeHttpRequests(a -> a
    .requestMatchers("/swagger-ui/**", "/v3/api-docs/**").authenticated()
    .anyRequest().permitAll());

UI vs spec - division of labor

Remember: Swagger UI is just a viewer. The source of truth is the OpenAPI spec generated from your code and annotations. Improve the docs by improving annotations, not the UI.

Quick Check

Confirm your Swagger UI knowledge.

Recap

You explored Swagger UI:

  • Served at /swagger-ui.html, backed by /v3/api-docs
  • Try it out sends live requests; Authorize adds tokens
  • Sort, filter and expansion are configurable via properties
  • Protect or disable the UI in production

คำถามที่พบบ่อย

บทเรียน “Swagger UI” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “Swagger UI” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Spring Boot 4 Microservices & REST APIs ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Spring Boot 4 Microservices & REST APIs มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “Swagger UI”

สำรวจและทดสอบ API แบบโต้ตอบ คุณปฏิบัติ Spring Boot 4 Microservices & REST APIs ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Spring Boot 4 Microservices & REST APIs หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Spring Boot 4 Microservices & REST APIs บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “Swagger UI” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Spring Boot 4 Microservices & REST APIs นี้ได้ไหม

ได้ บทเรียน Spring Boot 4 Microservices & REST APIs ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การเพิ่ม SpringDoc ในโครงงาน
  2. การจัดทำเอกสารปลายทางและโมเดล
  3. การปรับแต่งข้อกำหนด OpenAPI
  4. Swagger UI
← กลับไปที่ Spring Boot 4 Microservices & REST APIs