Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Enhance Response cache-control header

Abierto
#2,784 5 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Estancado

Línea de trabajo

Empieza revisando OpenAPI Header Object, la compatibilidad con JSON Schema y los ejemplos de Cache-Control de este issue. No se han identificado archivos del repositorio ni pruebas; completar el trabajo requeriría acordar y documentar una forma precisa e interoperable de representar directivas separadas por comas y directivas de clave-valor como max-age.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

headers http param serialization

I have been trying to use Open API to specify the expected Cache rules for some API routes

While defining such rules through the Expires and/or Pragma headers can be quite simple (a date for Expires & the no-cache constant for Pragma), they are not the modern way to do it. Pragma is deprecated, and Expires is ignored when Cache-Control is defined.

Cache-Control is also nowadays supported by all clients making it the most obvious solution to define the caching rules.

Unfortunately, the current OPEN API Header Object support looks a bit limited for Cache-Control. Using pure JSON Schema definition might produce unexpected behavior without dedicated context for this header or for headers having similar Design.

This header value is defined as a comma-seperated list of properties called directives
If all directives were simple strings I could write something like that if I allowed any of them (or restrict to the on I accept by design)

      responses:
        200:
          description: "The request was successfully treated."
          headers:
            Cache-Control: 
              schema:
                type: array
                items:
                  type: string
                  enum:
                  - public
                  - private
                  - no-cache
                  - no-store
                  - must-revalidate
                  - proxy-revalidate
                  - immutable
                  - no-transform
                  - only-if-cached

If I want my route to prevent response to be cached I can easily design it a more simple way

            Cache-Control: 
              schema:
                type: string
                enum:
                - no-store

Or with the last JSON-Schema edition support of constants

            Cache-Control: 
              schema:
                const: "no-store"

But some of the most important cache control properties are key value pairs like max-age=300

I tried to express it the most reiable still simple way using adavanced JSON Schema feature unfortunately not really well supported (yet?) by Open API implementations

Sample 1

  • Pro:
    • shortest
  • Cons:
    • forbid different property order
    • forbid potentially acceptable other cache-control properties
    • not really the most inspectable
            Cache-Control: 
              schema:
                const: "public, max-age=300"

Sample 2

  • Pro:
    • still short
  • Cons:
    • ⚠️❌ the specification doesn't say how to serialize the object
            Cache-Control: 
              schema:
                const: ["public", {"max-age": 300}]

Sample 3

  • Pro:
    • explicit, no need for const support
  • Cons:
    • very verbose
    • pretty sure enum not well supported for numbers
    • ⚠️❌ the specification still doesn't say how to serialize the object
            Cache-Control: 
              schema:
                type: array
                items:
                  allOf:
                  - type: string
                    enum:
                    - public
                  - type: object
                    properties:
                      max-age:
                        type: number
                        enum:
                        - 300
                      required:
                      - max-age
Lenguaje dominante
Markdown
Estrellas
31.2k
Forks
9.2k
Merge medio
2 d 9 h
PR fusionados (30 d)
17

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de OAI/OpenAPI-Specification

Todos los issues de OAI/OpenAPI-Specification

Issues similares

Más issues de Backend & API Design

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.